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
2011-02-17 13:34:56 -05:00
features Upped the aruba_timeout from 1 to 15 seconds 2011-01-31 16:45:04 -05:00
lib Fix assign_to_matcher for ruby 1.9.2: check for instance variables using symbols instead of strings 2011-02-17 13:34:56 -05:00
spec Support validates_presence_of with a class using ActiveModel::Validations. 2011-01-24 11:19:34 -05:00
.autotest fixed foreign key determination (http://tammer.lighthouseapp.com/projects/5807/tickets/8) 2008-01-21 14:30:10 +00:00
.gitignore Removed and gitignored Gemfile.lock and .bundle from the repository 2011-01-31 15:56:10 -05:00
CONTRIBUTION_GUIDELINES.rdoc Cosmetic: Whitespace 2010-06-22 14:59:33 -04:00
Gemfile Moved dependencies from the Gemfile to the gemspec 2011-01-31 16:45:13 -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 consistency 2010-12-15 18:48:29 -05:00
shoulda-matchers.gemspec Use ruby-debug19 on Ruby >= 1.9 (thanks to github.com/kollektiv) 2011-02-17 13:32:23 -05:00

= shoulda-matchers

{Official Documentation}[http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames]

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

Refer to the {shoulda}[https://github.com/thoughtbot/shoulda] gem if you want to know more
about using shoulda with Test::Unit.

=== ActiveRecord Matchers

Matchers to test associations and validations:

  describe Post do
    it { should belong_to(:user) }
    it { should have_many(:tags).through(:taggings) }

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

  describe User do
    it { should have_many(:posts) }

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

=== ActionController Matchers

Matchers to test common patterns:

  describe PostsController, "#show" do
    context "for a fictional user" do
      before do
        get :show, :id => 1
      end

      it { should assign_to(:user) }
      it { should respond_with(:success) }
      it { should render_template(:show) }
      it { should_not set_the_flash }
    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].
Thank you to all the {contributors}[https://github.com/thoughtbot/shoulda-matchers/contributors].

= 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.