Makes tests easy on the fingers and the eyes
Ruby Cucumber
Latest commit b411932 Oct 20, 2015 @rmm5t rmm5t Merge pull request #251 from lucianosousa/patch-1
Update .travis.yml

shoulda Gem Version Build Status

The shoulda gem is a meta gem with two dependencies:

The following describes different use cases and combinations.

rspec with shoulda-matchers

This is what thoughtbot currently does. We write tests like:

describe Post do
  it { should belong_to(:user) }
  it { should validate_presence_of(:title) }

The belong_to and validate_presence_of methods are the matchers. All matchers are Rails 3-specific.

Add rspec-rails and shoulda-matchers to the project's Gemfile:

group :test, :development do
  gem 'rspec-rails'
  gem 'shoulda-matchers'

test/unit with shoulda

For the folks who prefer Test::Unit, they'd write tests like:

class UserTest < Test::Unit::TestCase
  should have_many(:posts)
  should_not allow_value("blah").for(:email)

The have_many and allow_value methods are the same kind of matchers seen in the RSpec example. They come from the shoulda-matchers gem.

Add shoulda to the project's Gemfile:

group :test do
  gem 'shoulda'

test/unit with shoulda-context

If you're not testing a Rails project or don't want to use the matchers, you can use shoulda-context independently to write tests like:

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)

Add shoulda-context to the project's Gemfile:

group :test do
  gem 'shoulda-context'



Shoulda is maintained and funded by thoughtbot, inc

Thank you to all the contributors!

The names and logos for thoughtbot are trademarks of thoughtbot, inc.


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