Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Shoulda Roundup: Elegant, Maintainable Ruby Testing

By Matthew Lang / May 5, 2009

It's been a few weeks since Shoulda's 2.10 release so it's a good time to round up some of the new features and the best articles covering Shoulda.

For those unfamiliar with it, Shoulda is a library that allows you to write better and more understandable tests for your Ruby application. It's like overdrive for Test::Unit and RSpec.  Shoulda allows you to provide context to your tests so that you can group tests according to a specific feature or scenario your testing.

In the latest release of Shoulda a couple of key features should be mentioned.  Firstly, you now have matchers to use in controller specs, much like RSpec.

A second nice feature in this release is the ability to use block arguments within those macros that require expected strings.  By using blocks, you can now separate the Ruby code you're testing away from the individual test macro.

Mixing Cucumber with Test::Unit/Shoulda - If you're a Cucumber user, you might not know that BDD frameworks can also be used with Shoulda. The thoughtbot blog has an article highlighting the steps involved in setting up Cucumber with Shoulda that should allow you to get up and running in no time.

Shoulda looked at it sooner - John Nunemaker has written up his thoughts on using Shoulda and how his experience of toe dipping into Shoulda turned into becoming a hooked fan of the testing framework. Shoulda’s ability to be used with or without RSpec is a great for those new to the framework. Instead of fully committing to Shoulda, you can gradually immerse yourself in it’s features over a period of time.

Shmacros - Maxim Chernyak has released some custom macros he uses as part of Shoulda. With macros for delegates, callbacks and nested attributes, this would make a great extension to your application's tests.

Using Shoulda to test login - Justin Ball, has been looking into using Shoulda to test authentication.

Test Or Die: Validates Uniqueness Of, Shoulda and Factory Girl Edition - Finally Josh Nichols has been looking at applying Shoulda to an article by John Nunemaker. Josh's post is a great read for those looking to start out with Shoulda.

Post by Matthew Lang - Matthew Lang is an ERP developer with a keen interest in Ruby and Rails programming.


  1. Zoran Rilak says:

    Matt, please, correct the apostrophes: "your" is the genitive of "you", not "you are". "You are" is "you're". Also, "It's" is a shorthand for "it is", not the genitive of "it". Genitives don't use apostrophes, except in plural: "The Beatles's music".

  2. Zoran Rilak says:

    Er, I botched it. Genitives of pronouns don't use apostrophes. :)

  3. José Valim says:

    It would be nice to have a reference to Remarkable as well!

  4. Peter Cooper says:

    Sorry, I dropped the editing ball. I'm at RailsConf so I'm rather resource poor. I've updated the piece on Matt's behalf.

Other Posts to Enjoy

Twitter Mentions