I would like to write article about test driven development (TDD). How cool it is and why you should use it.
But right now I cannot find right words. So I am going to present some essential tools which you should consider when you want to (and you should) practise Ruby on Rails TDD.
Must have gems
- rspec-rails: Rspec is test framework. rspec-rails si Rspec for Rails applications. It is replacement of default Rails test framework.
- capybara: helps you to simulate user actions in your tests. This is must have for features (integration) tests.
Very good to have gems
- factory_girl_rails: factory_girl allows you to easily create new objects in your tests. In technical words it is a fixtures replacement.
- spork: dramatically reduces startup time of your tests. It pre-loads whole rails environment so you can run your tests very quickly. You need to restart it from time to time (to reload rails application), but it is great time saver anyway!
- launchy: allows you to use capybara's
save_and_open_pagemethod for opening current web page from feature test.
- shoulda-matchers: are some very common predefined matchers for your tests.
There is a lot of other gems which can help you with Rails TDD. But I use that ones mentioned above in every project. So this is how my TDD part of
Gemfile looks like.
group :test, :development do gem 'rspec-rails' gem 'spork' gem 'factory_girl_rails' end group :test do gem 'capybara' gem 'launchy' gem 'shoulda-matchers' end
p.s. if you are vim user then check rspec.vim for executing specs directly from vim