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:

http://github.com/bellmyer/functional_testing

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: