I\'m beginning the planning phase of creating a testing suite for my rails 3.0.8 application. I\'m trying to decide on which testing framework/gems to use. Normally I prefer
If you're beginning your journey with testing Rails application I would recommend you start doing it with TestUnit. You can find very nice course about best testing rails app and best practices on http://www.codeschool.com/courses/rails-testing-for-zombies If you're more experienced when it comes to testing you can try RSpec.
This Ruby Inside article, especially if you follow the links and read the comments, provides quite a thorough discussion of the relative merits of Test::Unit and RSpec. A key differentiator seems to be that:
Also see this part of Michael Hartl's Rails Tutorial for a comparison of RSpec and Cucumber.
You could use rspec
with cucumber
and webrat
gems which makes a great combination, if you have a large website. It will be cumbersome at first but later on it will be a huge benefit.
You could watch the following railscasts episodes to have more info about those gems:
155 Beginning with Cucumber
156 Webrat
157 RSpec Matchers & Macros
159 More on Cucumber
There are also some other gems like capybara
which is relatively new and promising, but honestly I didnt try it.
Both Test::Unit and Rspec are very nice solutions. As for me I prefer to use RSpec in my Rails project - because it has many automatic solutions like autotest, highlighting syntax, shortcut commands like rake spec
and other stuff that make using test easer. But in my plain ruby scripts I use Test::Unit - it is very lightweight and staightforward when you don't need complex testing (integrational and others)
The answer is matter of taste, use both in one project and find yourself what do you prefer. (I do Test::Unit, RSpec has to much sugar for me).
Update 2014: As Ruby 2.x has MiniTest built-in I would suggest to check MiniTest::Spec eventually which is simple BDD extension. You can mix "describe" and "it" blocks to nicely structure test contexts with. It also provides "must_be.." matchers if you want to more than assert
.
I prefer and use these gems for testing
To start with rspec take a look at this presentation. It contains all the necessary examples:
http://kerryb.github.com/iprug-rspec-presentation
Also read through these articles on rspec:
http://relishapp.com/rspec/rspec-rails