Testing is important. Your test suite should be just as elegant and thought through as your application code. Over the past year, I’ve landed on what I think is the perfect combination of gems for testing Rails/Ruby applications.
Here’s what my
Gemfile usually looks like when I’m starting out:
I always start with testing models heavily. This layer, after all, is essentially the internal API to your application, and ignoring low level tests here could result in difficult to debug edge cases further down the road. All my tests are written using RSpec, which is a no brainer. I’ll then combine this with Shoulda Matchers (for testing validations, associations), Factory Girl (for generating records to test against) and Faker (for quickly generating fake content in factories).
For mocks and stubs, I use the built in mocking framework that ships with RSpec. I’ve yet to run into any situations where I need more from a mocking framework, so this works well.
Tying it Together
Running tests isn’t much use if they’re slow. Doing TDD/BDD can be a huge boost in productivity, but only if your tests are fast and are only being run when they’re needed. To make tests run as quickly as possible, I use Guard + Spork. Guard will run the applicable spec for a file whenever it’s changed, and Spork preloads the rails environment at boot. If I’m working on a model, I can get near instant test results after saving the file by using this setup.
The above has worked incredibly well for me over the past year, and is what I used to build the test suite for 24pullrequests.com. Hopefully this will help you in making the right decisions on what to use with your stack!