Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (56 sloc) 2.477 kB
85c37c4 @gabebw Convert README to Markdown.
gabebw authored
1 # shoulda-matchers [![Build Status](https://secure.travis-ci.org/thoughtbot/shoulda-matchers.png?branch=master)](http://travis-ci.org/thoughtbot/shoulda-matchers)
2
3 [Official Documentation](http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames)
4
5 Test::Unit- and RSpec-compatible one-liners that test common Rails functionality.
6 These tests would otherwise be much longer, more complex, and error-prone.
7
8 Refer to the [shoulda](https://github.com/thoughtbot/shoulda) gem if you want to know more
9 about using shoulda with Test::Unit.
10
11 Please report bugs on the [shoulda issue tracker](https://github.com/thoughtbot/shoulda/issues).
12
13 ## ActiveRecord Matchers
14
15 Matchers to test associations:
16
17 describe Post do
18 it { should belong_to(:user) }
19 it { should have_many(:tags).through(:taggings) }
20 end
21
22 describe User do
23 it { should have_many(:posts) }
24 end
25
26 ## ActiveModel Matchers
27
28 Matchers to test validations and mass assignments:
29
30 describe Post do
31 it { should validate_uniqueness_of(:title) }
32 it { should validate_presence_of(:body).with_message(/wtf/) }
33 it { should validate_presence_of(:title) }
34 it { should validate_numericality_of(:user_id) }
35 end
36
37 describe User do
38 it { should_not allow_value("blah").for(:email) }
39 it { should allow_value("a@b.com").for(:email) }
40 it { should ensure_inclusion_of(:age).in_range(1..100) }
41 it { should_not allow_mass_assignment_of(:password) }
42 end
43
44 ## ActionController Matchers
45
46 Matchers to test common patterns:
47
48 describe PostsController, "#show" do
49 context "for a fictional user" do
50 before do
51 get :show, :id => 1
52 end
53
54 it { should assign_to(:user) }
55 it { should respond_with(:success) }
56 it { should render_template(:show) }
57 it { should_not set_the_flash }
58 end
59 end
60
61 ## Installation
62
63 In Rails 3 and Bundler, add the following to your Gemfile:
64
65 group :test do
66 gem "rspec-rails"
67 gem "shoulda-matchers"
68 end
69
70 Shoulda will automatically include matchers into the appropriate example groups.
71
72 ## Credits
73
74 Shoulda is maintained and funded by [thoughtbot](http://thoughtbot.com/community).
75 Thank you to all the [contributors](https://github.com/thoughtbot/shoulda-matchers/contributors).
76
77 ## License
78
79 Shoulda is Copyright © 2006-2010 thoughtbot, inc.
80 It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
Something went wrong with that request. Please try again.