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
2012-03-16 12:15:23 -04:00
features Generated rails app no longer requires a JS runtime. 2011-11-01 20:56:33 -04:00
gemfiles Merge branch 'no-js-runtime' of https://github.com/whitepages/shoulda-matchers 2011-11-16 13:36:26 -05:00
lib Update to modern thoughtbot style. 2012-03-16 12:15:23 -04:00
spec Update to modern thoughtbot style. 2012-03-16 12:15:23 -04:00
.autotest fixed foreign key determination (http://tammer.lighthouseapp.com/projects/5807/tickets/8) 2008-01-21 14:30:10 +00:00
.gitignore Update set_the_flash_matcher to also duplicate the used set to fix a bug in Rubinius 2011-09-19 01:05:07 +07:00
.travis.yml Change rbx-2.0 to rbx-18mode 2012-03-02 10:09:58 -05:00
Appraisals Remove uglifier and coffee-rails from the 3.1 gemfile, and modify spec_helper.rb to respect a BUNDLE_GEMFILE set on the command line. 2011-11-02 08:36:01 -07:00
CONTRIBUTION_GUIDELINES.rdoc Update the contribution guidelines. 2012-02-24 09:34:27 -05:00
Gemfile Use Bundler gem conventions. 2011-11-11 20:13:03 -05:00
MIT-LICENSE converted to the MIT license 2007-11-26 15:18:29 +00:00
Rakefile bundler/setup is important. 2011-11-18 18:28:57 -05:00
README.md Convert README to Markdown. 2012-03-09 11:57:31 -05:00
shoulda-matchers.gemspec Add rails to gemspec so that bundle exec works. 2012-03-16 12:14:49 -04:00

shoulda-matchers Build Status

Official Documentation

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 gem if you want to know more about using shoulda with Test::Unit.

Please report bugs on the shoulda issue tracker.

ActiveRecord Matchers

Matchers to test associations:

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

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

ActiveModel Matchers

Matchers to test validations and mass assignments:

describe Post do
  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_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 "rspec-rails"
  gem "shoulda-matchers"
end

Shoulda will automatically include matchers into the appropriate example groups.

Credits

Shoulda is maintained and funded by thoughtbot. Thank you to all the 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.