Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (36 sloc) 1.67 KB


Official Documentation

Shoulda's contexts make it easy to write understandable and maintainable tests for Test::Unit. It's fully compatible with your existing tests in Test::Unit, and requires no retooling to use.

Refer to the shoulda gem if you want to know more about using shoulda with Rails or RSpec.


Instead of writing Ruby methods with lots_of_underscores, shoulda-context adds context, setup, and should blocks…

class CalculatorTest < Test::Unit::TestCase
  context "a calculator" do
    setup do
      @calculator =

    should "add two numbers for the sum" do
      assert_equal 4, @calculator.sum(2, 2)

    should "multiply two numbers for the product" do
      assert_equal 10, @calculator.product(2, 5)

… which combine to produce the following test methods:

"test: A User instance should return its full name."
"test: A User instance with a profile should return true when sent #has_profile?."


It also has two additional Test::Unit assertions for working with Ruby's Array:

assert_same_elements([:a, :b, :c], [:c, :a, :b])
assert_contains(['a', '1'], /\d/)
assert_contains(['a', '1'], 'a')


Shoulda is maintained and funded by thoughtbot. Thank you to all the contributors.


Shoulda is Copyright © 2006-2010 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

Something went wrong with that request. Please try again.