Restful Controller Tests with Shoulda
I’ve developed an approach to restful controller tests for Ruby on Rails that I think is awesome. It uses Thoughtbot’s Shoulda test suite, along with Mocha for mocking and stubbing. My goals were maintainability, speed, and DRY (Don’t Repeat Yourself) code.
I’ll present five versions of my controller tests. The first is very basic, but covers testing all seven restful routes for each of three typical users: visitor, member, and admin. Subsequent versions increase the speed with stubbing, and DRY up the code for maxium readabiliy and ease of maintenance.
All five versions are already available as part of a basic Ruby on Rails application on GitHub:
View the tags to see the different versions. Download and play with them. I’ll add links to my testing tutorials as I complete them:
- Basic Restful Controller Tests
- Speeding Up Tests with Mocking and Stubbing
- DRY Tests with Abstraction
- DRYer Tests with Shoulda macros
- DRYest Tests with Refactoring