rspec-expectations 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +5 -0
- data/History.markdown +10 -0
- data/Rakefile +2 -2
- data/features/.nav +27 -0
- data/features/README.markdown +26 -2
- data/features/{matchers → built_in_matchers}/be.feature +31 -45
- data/features/{matchers → built_in_matchers}/be_within.feature +0 -0
- data/features/{matchers → built_in_matchers}/equality.feature +1 -1
- data/features/{matchers → built_in_matchers}/exist.feature +0 -0
- data/features/{matchers → built_in_matchers}/expect_change.feature +1 -1
- data/features/{matchers → built_in_matchers}/expect_error.feature +1 -1
- data/features/{matchers → built_in_matchers}/have.feature +0 -0
- data/features/{matchers → built_in_matchers}/include.feature +0 -0
- data/features/{matchers → built_in_matchers}/match.feature +0 -0
- data/features/built_in_matchers/operators.feature +221 -0
- data/features/{matchers → built_in_matchers}/predicates.feature +1 -1
- data/features/{matchers → built_in_matchers}/respond_to.feature +0 -0
- data/features/{matchers → built_in_matchers}/satisfy.feature +1 -1
- data/features/{matchers → built_in_matchers}/throw_symbol.feature +1 -1
- data/features/{matchers → built_in_matchers}/types.feature +0 -0
- data/features/{matchers → custom_matchers}/access_running_example.feature +1 -1
- data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +1 -1
- data/features/{expectations/customized_message.feature → customized_message.feature} +0 -0
- data/features/{expectations/diffing.feature → diffing.feature} +12 -12
- data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +0 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/be.rb +4 -4
- data/lib/rspec/matchers/change.rb +25 -19
- data/lib/rspec/matchers/operator_matcher.rb +3 -3
- data/spec/rspec/matchers/be_spec.rb +8 -8
- data/spec/rspec/matchers/operator_matcher_spec.rb +10 -10
- metadata +55 -57
- data/features/expectations/attribute_of_subject.feature +0 -19
- data/features/matchers/operators.feature +0 -280
@@ -1,19 +0,0 @@
|
|
1
|
-
Feature: attribute of subject
|
2
|
-
|
3
|
-
In order to get more meaningful failure messages
|
4
|
-
As a spec author
|
5
|
-
I want RSpec to tell me what attribute a matcher applies
|
6
|
-
to when using the its(:attribute) technique
|
7
|
-
|
8
|
-
Scenario: eq matcher fails
|
9
|
-
Given a file named "example_spec.rb" with:
|
10
|
-
"""
|
11
|
-
describe "an array" do
|
12
|
-
subject { [] }
|
13
|
-
its(:size) { should eq(1) } # intentionally fail
|
14
|
-
end
|
15
|
-
"""
|
16
|
-
|
17
|
-
When I run "rspec example_spec.rb -fdoc"
|
18
|
-
Then the output should contain "Failure/Error: its(:size) { should eq(1) }"
|
19
|
-
And the output should contain "expected 1"
|
@@ -1,280 +0,0 @@
|
|
1
|
-
Feature: Operator matchers
|
2
|
-
|
3
|
-
RSpec provides a number of matchers that are based on Ruby's built-in
|
4
|
-
operators. These mostly work like you expect. For example, each of these pass:
|
5
|
-
|
6
|
-
* 7.should == 7
|
7
|
-
* 25.2.should < 100
|
8
|
-
* 8.should > 7
|
9
|
-
* 17.should <= 17
|
10
|
-
* 3.should >= 2
|
11
|
-
* [1, 2, 3].should == [1, 2, 3]
|
12
|
-
* "this is a string".should =~ /^this/
|
13
|
-
* "this is a string".should_not =~ /^that/
|
14
|
-
* String.should === "this is a string"
|
15
|
-
|
16
|
-
RSpec also provides a `=~` matcher for arrays that disregards differences in
|
17
|
-
the ording between the actual and expected array. For example:
|
18
|
-
|
19
|
-
* [1, 2, 3].should =~ [2, 3, 1] # pass
|
20
|
-
* [:a, :c, :b].should =~ [:a, :c] # fail
|
21
|
-
|
22
|
-
Scenario: numeric operator matchers
|
23
|
-
Given a file named "numeric_operator_matchers_spec.rb" with:
|
24
|
-
"""
|
25
|
-
describe 18 do
|
26
|
-
it { should == 18 }
|
27
|
-
it { should < 20 }
|
28
|
-
it { should > 15 }
|
29
|
-
it { should <= 19 }
|
30
|
-
it { should >= 17 }
|
31
|
-
|
32
|
-
it { should_not == 28 }
|
33
|
-
it { should_not < 15 }
|
34
|
-
it { should_not > 20 }
|
35
|
-
it { should_not <= 17 }
|
36
|
-
it { should_not >= 19 }
|
37
|
-
|
38
|
-
# deliberate failures
|
39
|
-
it { should == 28 }
|
40
|
-
it { should < 15 }
|
41
|
-
it { should > 20 }
|
42
|
-
it { should <= 17 }
|
43
|
-
it { should >= 19 }
|
44
|
-
|
45
|
-
it { should_not == 18 }
|
46
|
-
it { should_not < 20 }
|
47
|
-
it { should_not > 15 }
|
48
|
-
it { should_not <= 19 }
|
49
|
-
it { should_not >= 17 }
|
50
|
-
end
|
51
|
-
"""
|
52
|
-
When I run "rspec numeric_operator_matchers_spec.rb"
|
53
|
-
Then the output should contain "20 examples, 10 failures"
|
54
|
-
And the output should contain:
|
55
|
-
"""
|
56
|
-
Failure/Error: it { should == 28 }
|
57
|
-
expected: 28,
|
58
|
-
got: 18 (using ==)
|
59
|
-
"""
|
60
|
-
And the output should contain:
|
61
|
-
"""
|
62
|
-
Failure/Error: it { should < 15 }
|
63
|
-
expected: < 15,
|
64
|
-
got: 18
|
65
|
-
"""
|
66
|
-
And the output should contain:
|
67
|
-
"""
|
68
|
-
Failure/Error: it { should > 20 }
|
69
|
-
expected: > 20,
|
70
|
-
got: 18
|
71
|
-
"""
|
72
|
-
And the output should contain:
|
73
|
-
"""
|
74
|
-
Failure/Error: it { should <= 17 }
|
75
|
-
expected: <= 17,
|
76
|
-
got: 18
|
77
|
-
"""
|
78
|
-
And the output should contain:
|
79
|
-
"""
|
80
|
-
Failure/Error: it { should >= 19 }
|
81
|
-
expected: >= 19,
|
82
|
-
got: 18
|
83
|
-
"""
|
84
|
-
And the output should contain:
|
85
|
-
"""
|
86
|
-
Failure/Error: it { should_not == 18 }
|
87
|
-
expected not: == 18,
|
88
|
-
got: 18
|
89
|
-
"""
|
90
|
-
And the output should contain:
|
91
|
-
"""
|
92
|
-
Failure/Error: it { should_not < 20 }
|
93
|
-
expected not: < 20,
|
94
|
-
got: 18
|
95
|
-
"""
|
96
|
-
And the output should contain:
|
97
|
-
"""
|
98
|
-
Failure/Error: it { should_not > 15 }
|
99
|
-
expected not: > 15,
|
100
|
-
got: 18
|
101
|
-
"""
|
102
|
-
And the output should contain:
|
103
|
-
"""
|
104
|
-
Failure/Error: it { should_not <= 19 }
|
105
|
-
expected not: <= 19,
|
106
|
-
got: 18
|
107
|
-
"""
|
108
|
-
And the output should contain:
|
109
|
-
"""
|
110
|
-
Failure/Error: it { should_not >= 17 }
|
111
|
-
expected not: >= 17,
|
112
|
-
got: 18
|
113
|
-
"""
|
114
|
-
|
115
|
-
Scenario: string operator matchers
|
116
|
-
Given a file named "string_operator_matchers_spec.rb" with:
|
117
|
-
"""
|
118
|
-
describe "Strawberry" do
|
119
|
-
it { should == "Strawberry" }
|
120
|
-
it { should < "Tomato" }
|
121
|
-
it { should > "Apple" }
|
122
|
-
it { should <= "Turnip" }
|
123
|
-
it { should >= "Banana" }
|
124
|
-
it { should =~ /berry/ }
|
125
|
-
|
126
|
-
it { should_not == "Peach" }
|
127
|
-
it { should_not < "Cranberry" }
|
128
|
-
it { should_not > "Zuchini" }
|
129
|
-
it { should_not <= "Potato" }
|
130
|
-
it { should_not >= "Tomato" }
|
131
|
-
it { should_not =~ /apple/ }
|
132
|
-
|
133
|
-
it "reports that it is a string using ===" do
|
134
|
-
String.should === subject
|
135
|
-
end
|
136
|
-
|
137
|
-
# deliberate failures
|
138
|
-
it { should == "Peach" }
|
139
|
-
it { should < "Cranberry" }
|
140
|
-
it { should > "Zuchini" }
|
141
|
-
it { should <= "Potato" }
|
142
|
-
it { should >= "Tomato" }
|
143
|
-
it { should =~ /apple/ }
|
144
|
-
|
145
|
-
it { should_not == "Strawberry" }
|
146
|
-
it { should_not < "Tomato" }
|
147
|
-
it { should_not > "Apple" }
|
148
|
-
it { should_not <= "Turnip" }
|
149
|
-
it { should_not >= "Banana" }
|
150
|
-
it { should_not =~ /berry/ }
|
151
|
-
|
152
|
-
it "fails a spec asserting that it is a symbol" do
|
153
|
-
Symbol.should === subject
|
154
|
-
end
|
155
|
-
end
|
156
|
-
"""
|
157
|
-
When I run "rspec string_operator_matchers_spec.rb"
|
158
|
-
Then the output should contain "26 examples, 13 failures"
|
159
|
-
And the output should contain:
|
160
|
-
"""
|
161
|
-
Failure/Error: it { should == "Peach" }
|
162
|
-
expected: "Peach",
|
163
|
-
got: "Strawberry" (using ==)
|
164
|
-
"""
|
165
|
-
And the output should contain:
|
166
|
-
"""
|
167
|
-
Failure/Error: it { should < "Cranberry" }
|
168
|
-
expected: < "Cranberry",
|
169
|
-
got: "Strawberry"
|
170
|
-
"""
|
171
|
-
And the output should contain:
|
172
|
-
"""
|
173
|
-
Failure/Error: it { should > "Zuchini" }
|
174
|
-
expected: > "Zuchini",
|
175
|
-
got: "Strawberry"
|
176
|
-
"""
|
177
|
-
And the output should contain:
|
178
|
-
"""
|
179
|
-
Failure/Error: it { should <= "Potato" }
|
180
|
-
expected: <= "Potato",
|
181
|
-
got: "Strawberry"
|
182
|
-
"""
|
183
|
-
And the output should contain:
|
184
|
-
"""
|
185
|
-
Failure/Error: it { should >= "Tomato" }
|
186
|
-
expected: >= "Tomato",
|
187
|
-
got: "Strawberry"
|
188
|
-
"""
|
189
|
-
And the output should contain:
|
190
|
-
"""
|
191
|
-
Failure/Error: it { should =~ /apple/ }
|
192
|
-
expected: /apple/,
|
193
|
-
got: "Strawberry" (using =~)
|
194
|
-
"""
|
195
|
-
And the output should contain:
|
196
|
-
"""
|
197
|
-
Failure/Error: it { should_not == "Strawberry" }
|
198
|
-
expected not: == "Strawberry",
|
199
|
-
got: "Strawberry"
|
200
|
-
"""
|
201
|
-
And the output should contain:
|
202
|
-
"""
|
203
|
-
Failure/Error: it { should_not < "Tomato" }
|
204
|
-
expected not: < "Tomato",
|
205
|
-
got: "Strawberry"
|
206
|
-
"""
|
207
|
-
And the output should contain:
|
208
|
-
"""
|
209
|
-
Failure/Error: it { should_not > "Apple" }
|
210
|
-
expected not: > "Apple",
|
211
|
-
got: "Strawberry"
|
212
|
-
"""
|
213
|
-
And the output should contain:
|
214
|
-
"""
|
215
|
-
Failure/Error: it { should_not <= "Turnip" }
|
216
|
-
expected not: <= "Turnip",
|
217
|
-
got: "Strawberry"
|
218
|
-
"""
|
219
|
-
And the output should contain:
|
220
|
-
"""
|
221
|
-
Failure/Error: it { should_not >= "Banana" }
|
222
|
-
expected not: >= "Banana",
|
223
|
-
got: "Strawberry"
|
224
|
-
"""
|
225
|
-
And the output should contain:
|
226
|
-
"""
|
227
|
-
Failure/Error: it { should_not =~ /berry/ }
|
228
|
-
expected not: =~ /berry/,
|
229
|
-
got: "Strawberry"
|
230
|
-
"""
|
231
|
-
And the output should contain:
|
232
|
-
"""
|
233
|
-
Failure/Error: Symbol.should === subject
|
234
|
-
expected: "Strawberry",
|
235
|
-
got: Symbol (using ===)
|
236
|
-
"""
|
237
|
-
|
238
|
-
Scenario: array operator matchers
|
239
|
-
Given a file named "array_operator_matchers_spec.rb" with:
|
240
|
-
"""
|
241
|
-
describe [1, 2, 3] do
|
242
|
-
it { should == [1, 2, 3] }
|
243
|
-
it { should_not == [1, 3, 2] }
|
244
|
-
|
245
|
-
it { should =~ [1, 2, 3] }
|
246
|
-
it { should =~ [1, 3, 2] }
|
247
|
-
it { should =~ [2, 1, 3] }
|
248
|
-
it { should =~ [2, 3, 1] }
|
249
|
-
it { should =~ [3, 1, 2] }
|
250
|
-
it { should =~ [3, 2, 1] }
|
251
|
-
|
252
|
-
# deliberate failures
|
253
|
-
it { should_not == [1, 2, 3] }
|
254
|
-
it { should == [1, 3, 2] }
|
255
|
-
it { should =~ [1, 2, 1] }
|
256
|
-
end
|
257
|
-
"""
|
258
|
-
When I run "rspec array_operator_matchers_spec.rb"
|
259
|
-
Then the output should contain "11 examples, 3 failures"
|
260
|
-
And the output should contain:
|
261
|
-
"""
|
262
|
-
Failure/Error: it { should_not == [1, 2, 3] }
|
263
|
-
expected not: == [1, 2, 3],
|
264
|
-
got: [1, 2, 3]
|
265
|
-
"""
|
266
|
-
And the output should contain:
|
267
|
-
"""
|
268
|
-
Failure/Error: it { should == [1, 3, 2] }
|
269
|
-
expected: [1, 3, 2],
|
270
|
-
got: [1, 2, 3] (using ==)
|
271
|
-
"""
|
272
|
-
And the output should contain:
|
273
|
-
"""
|
274
|
-
Failure/Error: it { should =~ [1, 2, 1] }
|
275
|
-
expected collection contained: [1, 1, 2]
|
276
|
-
actual collection contained: [1, 2, 3]
|
277
|
-
the missing elements were: [1]
|
278
|
-
the extra elements were: [3]
|
279
|
-
"""
|
280
|
-
|