forked from joshknowles/rspec-on-rails-matchers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
195 lines (137 loc) · 4.51 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
rspec-on-rails-matchers
=======================
Setup
------
Dependencies:
-------------
* rspec
* rspec_on_rails
Overview
--------
Adds the following RSpec matchers:
* Associations:
Verify that the association has been defined. (doesn't verify that the association works!)
object.should have_many(:association)
example: @post.should have_many(:comments)
TM snippet: [mshm + tab] (Model Should Have Many)
object.should belong_to(:association)
example: @comment.should belong_to(:post)
TM snippet: [msbt + tab]
object.should have_one(:association)
user.should have_one(:social_security_number)
TM snippet: [msho + tab]
object.should have_and_belong_to_many(:association)
project.should have_and_belong_to_many(:categories)
TM snippet: [mshabtm + tab]
* Validations:
Verify that a validation has been defined. (doesn't test the validation itself)
object.should validate_presence_of(:attribute)
TM snippet: [msvp + tab]
object.should validate_confirmation_of(:attribute)
TM snippet: [msvc + tab]
object.should validate_uniqueness_of(:attribute)
TM snippet: [msvu + tab]
object.should validate_length_of(:attribute, :within => 5..10)
object.should validate_length_of(:attribute, :is => 5)
TM snippet: [msvl + tab]
object.should validate_numericality_of(:attribute, :greater_than => 1)
object.should validate_numericality_of(:attribute, :less_than_or_equal_to => 99)
TM snippet: [msvn + tab]
* Observers:
Verify that the observer is observing a class. (doesn't verify that the observation works)
object.should observe(:model)
example: GroupObserver.should observe(Group)
* Views:
Verifies that the views contains some tags.
response.should have_form_posting_to(url_or_path)
TM snippet: [hfpt + tab]
response.should have_form_putting_to(url_or_path)
response.should have_text_field_for(:attribute)
TM snippet: [htff + tab]
response.should have_label_for(:attribute)
TM snippet: [hlf + tab]
response.should have_password_field_for(:attribute)
TM snippet: [hpff + tab]
response.should have_checkbox_for(:attribute)
TM snippet: [hcf + tab]
response.should have_submit_button
TM snippet: [hsb + tab]
response.should have_link_to(url_or_path, "optional_text")
TM snippet: [hlt + tab]
* nested view tests:
for instance:
response.should have_form_posting_to(url_or_path) do
with_text_field_for(:attribute)
end
with_text_field_for(:attribute)
TM snippet: [wtff + tab]
with_label_for(:attribute)
TM snippet: [wlf + tab]
with_password_field_for(:attribute)
TM snippet: [wpff + tab]
with_checkbox_for(:attribute)
TM snippet: [wcf + tab]
with_submit_button
TM snippet: [wsb + tab]
with_link_to(url_or_path, "optional_text")
TM snippet: [wlt + tab]
Usage:
------
In your view spec:
it "should render new form" do
render "/users/new.html.erb"
response.should have_form_posting_to(users_path) do
with_text_field_for(:user_name)
with_text_area_for(:user_address)
with_text_field_for(:user_login)
with_text_field_for(:user_email)
with_submit_button
end
end
In your model spec:
describe User do
before(:each) do
@user = User.new
end
it "should have many posts" do
@user.should have_many(:posts)
end
it "should belong to a group" do
@user.should belong_to(:group)
end
it do
@user.should validate_presence_of(:email)
end
it do
@user.should validate_uniqueness_of(:email)
end
it do
@user.should validate_uniqueness_of(:login)
end
it do
@user.should validate_presence_of(:login)
end
it do
@user.should validate_presence_of(:name)
end
it do
@user.should validate_length_of(:password, :between => 4..40)
end
it do
@user.should validate_numericality_of(:age, :greater_than_or_equal_to => 21)
end
it do
@user.should validate_confirmation_of(:password)
end
end
Core Contributors
-----------------
* Josh Knowles <[email protected]>
* Bryan Helmkamp <[email protected]>
* Matt Aimonetti <[email protected]>
Contributors
-------------
* ckknight
* Matt Pelletier
* Luke Melia
Copyright (c) 2008 The Plugin Development Team, released under the MIT license