It seems everyone is using rspec these days, yet rails still comes bundled with test::unit by default.
Are there any major advantages of rspec over test unit? It's hard to get straight info on this subject...
It seems everyone is using rspec these days, yet rails still comes bundled with test::unit by default.
Are there any major advantages of rspec over test unit? It's hard to get straight info on this subject...
There is a typically lot of focus on syntax in these discussions, which is certainly subjective, but RSpec offers some useful features that are no where to be seen in test/unit, minitest, or their extension libraries. The three biggies, for me, are:
readable output (TURN helps w/ this, but it doesn't have things like printing out the command you need to copy to run an individual example that failed).
sensible CTRL-C. In rspec-2, when you hit CTRL-C, the example that is running at that moment finishes (you can hit CTRL-C a 2nd time to stop it immediately), and all of it's after hooks run, and you get the same output report that you would get otherwise. How many times have you seen an F among the first 50 or so dots, and been given no indication of which tests actually failed. With rspec-2, this does not happen.
metadata associated with every example and group. RSpec uses this to support selection of which examples to run based on a variety of criteria (location, names, ruby versions, command line tags, etc), plus inclusion/extension of modules based on same.
There's more, but that's just to give you an idea. Of course, I'm biased, so take my recommendations with a grain of salt.
FWIW, David
rails still comes bundled with test::unit by default.
Might be because
I think this is mostly subjective. I prefer the more tradional assert
based testing over rspec's matcher-based assertions, so I stick with Test::Unit
. One area where I think rspec is more powerful though is the built in stubbing stuff (you have to use additional libraries to accomplish this with Test::Unit
).