1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

brand-spanking new documentation

This commit is contained in:
Dan Croak 2010-12-15 18:44:57 -05:00
parent 013412f6af
commit b62be03351

View file

@ -1,52 +1,50 @@
= shoulda-matchers = 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. Test::Unit- and RSpec-compatible one-liners that test common Rails functionality.
These tests would otherwise be much longer, more complex, and error-prone. 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 === ActiveRecord Matchers
Matchers to test associations and validations: Matchers to test associations and validations:
class PostTest < Test::Unit::TestCase describe Post do
should belong_to(:user) it { should belong_to(:user) }
should have_many(:tags).through(:taggings) it { should have_many(:tags).through(:taggings) }
should validate_uniqueness_of(:title) it { should validate_uniqueness_of(:title) }
should validate_presence_of(:body).with_message(/wtf/) it { should validate_presence_of(:body).with_message(/wtf/) }
should validate_presence_of(:title) it { should validate_presence_of(:title) }
should validate_numericality_of(:user_id) it { should validate_numericality_of(:user_id) }
end end
class UserTest < Test::Unit::TestCase describe User do
should have_many(:posts) it { should have_many(:posts) }
should_not allow_value("blah").for(:email) it { should_not allow_value("blah").for(:email) }
should_not allow_value("b lah").for(:email) it { should allow_value("a@b.com").for(:email) }
should allow_value("a@b.com").for(:email) it { should ensure_inclusion_of(:age).in_range(1..100) }
should allow_value("asdf@asdf.com").for(:email) it { should_not allow_mass_assignment_of(:password) }
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 end
=== Controller Matchers === Controller Matchers
Matchers to test common patterns: Matchers to test common patterns:
class PostsControllerTest < ActionController::TestCase describe PostsController, "#show" do
context "on GET to :show for first record" do context "for a fictional user" do
setup do before do
get :show, :id => 1 get :show, :id => 1
end end
should assign_to(:user) it { should assign_to(:user) }
should respond_with(:success) it { should respond_with(:success) }
should render_template(:show) it { should render_template(:show) }
should_not set_the_flash it { should_not set_the_flash }
should "do something else really cool" do
assert_equal 1, assigns(:user).id
end
end end
end end
@ -64,6 +62,7 @@ Shoulda will automatically include matchers into the appropriate example groups.
= Credits = Credits
Shoulda is maintained and funded by {thoughtbot}[http://thoughtbot.com/community]. 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 = License