2010-12-15 22:56:11 +00:00
|
|
|
= shoulda-matchers
|
2007-04-05 18:26:25 +00:00
|
|
|
|
2010-12-15 23:44:57 +00:00
|
|
|
{Official Documentation}[http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames]
|
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
Test::Unit- and RSpec-compatible one-liners that test common Rails functionality.
|
|
|
|
These tests would otherwise be much longer, more complex, and error-prone.
|
2007-04-05 18:26:25 +00:00
|
|
|
|
2010-12-15 23:44:57 +00:00
|
|
|
Refer to the {shoulda}[https://github.com/thoughtbot/shoulda] gem if you want to know more
|
|
|
|
about using shoulda with Test::Unit.
|
|
|
|
|
2011-09-07 15:52:17 +00:00
|
|
|
Please report bugs on the {shoulda issue tracker}[https://github.com/thoughtbot/shoulda/issues].
|
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
=== ActiveRecord Matchers
|
2007-04-05 18:26:25 +00:00
|
|
|
|
2011-05-06 11:51:12 +00:00
|
|
|
Matchers to test associations:
|
2007-07-24 20:16:01 +00:00
|
|
|
|
2010-12-15 23:44:57 +00:00
|
|
|
describe Post do
|
|
|
|
it { should belong_to(:user) }
|
|
|
|
it { should have_many(:tags).through(:taggings) }
|
2011-05-06 11:51:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe User do
|
|
|
|
it { should have_many(:posts) }
|
|
|
|
end
|
2007-07-24 20:16:01 +00:00
|
|
|
|
2011-05-06 11:51:12 +00:00
|
|
|
=== ActiveModel Matchers
|
|
|
|
|
2011-05-09 16:17:35 +00:00
|
|
|
Matchers to test validations and mass assignments:
|
2011-05-06 11:51:12 +00:00
|
|
|
|
|
|
|
describe Post do
|
2010-12-15 23:44:57 +00:00
|
|
|
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) }
|
2007-07-24 20:16:01 +00:00
|
|
|
end
|
|
|
|
|
2010-12-15 23:44:57 +00:00
|
|
|
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) }
|
2007-07-24 20:16:01 +00:00
|
|
|
end
|
|
|
|
|
2010-12-15 23:48:29 +00:00
|
|
|
=== ActionController Matchers
|
2010-06-17 14:17:30 +00:00
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
Matchers to test common patterns:
|
2007-07-24 20:16:01 +00:00
|
|
|
|
2010-12-15 23:44:57 +00:00
|
|
|
describe PostsController, "#show" do
|
|
|
|
context "for a fictional user" do
|
|
|
|
before do
|
2009-05-27 17:58:39 +00:00
|
|
|
get :show, :id => 1
|
|
|
|
end
|
2007-07-24 20:16:01 +00:00
|
|
|
|
2010-12-15 23:44:57 +00:00
|
|
|
it { should assign_to(:user) }
|
|
|
|
it { should respond_with(:success) }
|
|
|
|
it { should render_template(:show) }
|
|
|
|
it { should_not set_the_flash }
|
2007-07-24 20:16:01 +00:00
|
|
|
end
|
|
|
|
end
|
2010-06-17 14:17:30 +00:00
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
= Installation
|
2010-06-22 20:30:54 +00:00
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
In Rails 3 and Bundler, add the following to your Gemfile:
|
2010-06-22 20:30:54 +00:00
|
|
|
|
|
|
|
group :test do
|
2010-12-15 22:56:11 +00:00
|
|
|
gem "rspec-rails"
|
2011-03-18 19:53:47 +00:00
|
|
|
gem "shoulda-matchers"
|
2010-06-22 20:30:54 +00:00
|
|
|
end
|
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
Shoulda will automatically include matchers into the appropriate example groups.
|
2010-06-22 20:30:54 +00:00
|
|
|
|
2007-07-24 20:16:01 +00:00
|
|
|
= Credits
|
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
Shoulda is maintained and funded by {thoughtbot}[http://thoughtbot.com/community].
|
2010-12-15 23:44:57 +00:00
|
|
|
Thank you to all the {contributors}[https://github.com/thoughtbot/shoulda-matchers/contributors].
|
2007-07-24 20:16:01 +00:00
|
|
|
|
|
|
|
= License
|
2007-04-05 18:26:25 +00:00
|
|
|
|
2010-12-15 22:56:11 +00:00
|
|
|
Shoulda is Copyright © 2006-2010 thoughtbot, inc.
|
|
|
|
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|