DEV Community

Discussion on: Testing 1, 2, 3... RSpec Basics and Tips for RoR.

Collapse
 
sturpin profile image
Sergio TurpĆ­n • Edited

I take note! šŸ˜Š
Sorry for my ignorance, do you think that with minitest (github.com/seattlerb/minitest) you can do the same tests as with Rspec?

I know it's bad practice... but I never wrote a test in my application and now that I have seen your article, you have aroused my curiosity šŸ˜„

Collapse
 
djuber profile image
Daniel Uber • Edited

Hi Sergio,

I think yes, you can use minitest (rails does this for its internal tests, via ActiveSupport::TestCase ) and ruby supports this as part of the stdlib in Test::Unit::TestCase . There are gems to bring a lot of the "expectation" DSL from RSpec into Minitest.

A lot of application developers (the team behind DEV included) use RSpec, but there's certainly nothing requiring you to use RSpec with a rails app. There's a lot of community mindshare around RSpec, but there are always dissenting opinions (people coming from xUnit style testing frameworks in other languages find parts of minitest less weird, people trying to limit complexity prefer the equivalence of a unit test with the code that calls it, some people are really upset about the use of nested contexts and overriden let declarations). If you already have experience with Minitest, and aren't also working with a team of RSpec advocates or experts, use what works best for you. If you're trying to capture some of the "nice to have" features RSpec adds, there are usually gems, but you might have to do a little extra reading or extra configuration to figure things out. This might include the expect syntax and some of the collection matchers.

A little dated (it's talking about Rails 4), but blowmage.com/2013/07/08/minitest-s... might be a helpful read to get your bearings.

Collapse
 
sturpin profile image
Sergio TurpĆ­n

Hi Daniel,

Thank you so much!! šŸ˜Š Your explanation has been excellent. I generally work alone and wanted to start doing simple unit tests and I honestly didn't know where to start šŸ˜….

If you had to start, which one would you start with?

Thread Thread
 
djuber profile image
Daniel Uber

I am personally comfortable with RSpec so I would reach for it by default in a personal project, however starting with either should be fine. The easy answer is "find the testing tutorial for your framework, and use it until you have a reason to change".

For rails that's probably the testing guide. The available assertions section probably gives you a "vocabulary" list to get started and suggest what you can test out of the box. The guide for rails is written for Minitest. RSpec's documentation also has details on how to integrate with rails projects (and there are going to be lots of examples available on github for both setups).

Usually, once you've got the first test running (it can find your code, it can load a class and call its methods) the rest is easy, and your problems may center more on making testable code (so the tests are easier to write) than configuring your test framework.

Thread Thread
 
sturpin profile image
Sergio TurpĆ­n

Thank you very much for your opinion, it's very helpful šŸ˜ƒ