1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
Simple one-liner tests for common Rails functionality
Find a file
2010-12-15 17:56:11 -05:00
.bundle Extracted the context framework, switched to rspec 2010-12-14 17:02:03 -05:00
features Move into the Matchers namespace 2010-12-15 17:34:19 -05:00
lib Move into the Matchers namespace 2010-12-15 17:34:19 -05:00
spec Move into the Matchers namespace 2010-12-15 17:34:19 -05:00
.autotest fixed foreign key determination (http://tammer.lighthouseapp.com/projects/5807/tickets/8) 2008-01-21 14:30:10 +00:00
.gitignore Fixed rspec2/rails3 integration; added integration tests for macros/matchers/rspec in rails 2 and 3 using cucumber 2010-06-23 14:46:28 -04:00
CONTRIBUTION_GUIDELINES.rdoc Cosmetic: Whitespace 2010-06-22 14:59:33 -04:00
Gemfile Got cucumber features passing with aruba and extracted context framework 2010-12-15 14:24:05 -05:00
Gemfile.lock Got cucumber features passing with aruba and extracted context framework 2010-12-15 14:24:05 -05:00
MIT-LICENSE converted to the MIT license 2007-11-26 15:18:29 +00:00
Rakefile Move into the Matchers namespace 2010-12-15 17:34:19 -05:00
README.rdoc new shoulda-matchers README 2010-12-15 17:56:11 -05:00
shoulda-matchers.gemspec Move into the Matchers namespace 2010-12-15 17:34:19 -05:00

= shoulda-matchers

Test::Unit- and RSpec-compatible one-liners that test common Rails functionality.
These tests would otherwise be much longer, more complex, and error-prone.

=== ActiveRecord Matchers

Matchers to test associations and validations:

  class PostTest < Test::Unit::TestCase
    should belong_to(:user)
    should have_many(:tags).through(:taggings)

    should validate_uniqueness_of(:title)
    should validate_presence_of(:body).with_message(/wtf/)
    should validate_presence_of(:title)
    should validate_numericality_of(:user_id)
  end

  class UserTest < Test::Unit::TestCase
    should have_many(:posts)

    should_not allow_value("blah").for(:email)
    should_not allow_value("b lah").for(:email)
    should allow_value("a@b.com").for(:email)
    should allow_value("asdf@asdf.com").for(:email)
    should ensure_inclusion_of(:email).in_range(1..100)
    should ensure_inclusion_of(:age).in_range(1..100)
    should_not allow_mass_assignment_of(:password)
  end

=== Controller Matchers

Matchers to test common patterns:

  class PostsControllerTest < ActionController::TestCase
    context "on GET to :show for first record" do
      setup do
        get :show, :id => 1
      end

      should assign_to(:user)
      should respond_with(:success)
      should render_template(:show)
      should_not set_the_flash

      should "do something else really cool" do
        assert_equal 1, assigns(:user).id
      end
    end
  end

= Installation

In Rails 3 and Bundler, add the following to your Gemfile:

  group :test do
    gem "shoulda-matchers"
    gem "rspec-rails"
  end

Shoulda will automatically include matchers into the appropriate example groups.

= Credits

Shoulda is maintained and funded by {thoughtbot}[http://thoughtbot.com/community].

= License

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