rspec-expectations 2.0.0.beta.19 → 2.0.0.beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Rakefile +0 -7
- data/VERSION +1 -1
- data/features/matchers/define_matcher.feature +40 -4
- data/lib/rspec/expectations/extensions.rb +1 -0
- data/lib/rspec/expectations/extensions/array.rb +7 -0
- data/lib/rspec/matchers/dsl.rb +4 -0
- data/lib/rspec/matchers/throw_symbol.rb +2 -2
- data/rspec-expectations.gemspec +10 -15
- data/spec/rspec/expectations/differ_spec.rb +3 -3
- data/spec/rspec/expectations/handler_spec.rb +2 -2
- data/spec/rspec/matchers/be_spec.rb +68 -68
- data/spec/rspec/matchers/change_spec.rb +43 -43
- data/spec/rspec/matchers/description_generation_spec.rb +1 -1
- data/spec/rspec/matchers/eql_spec.rb +5 -5
- data/spec/rspec/matchers/equal_spec.rb +5 -5
- data/spec/rspec/matchers/exist_spec.rb +1 -1
- data/spec/rspec/matchers/has_spec.rb +11 -11
- data/spec/rspec/matchers/have_spec.rb +39 -39
- data/spec/rspec/matchers/include_spec.rb +14 -14
- data/spec/rspec/matchers/match_array_spec.rb +10 -10
- data/spec/rspec/matchers/match_spec.rb +10 -10
- data/spec/rspec/matchers/operator_matcher_spec.rb +24 -24
- data/spec/rspec/matchers/raise_error_spec.rb +46 -46
- data/spec/rspec/matchers/satisfy_spec.rb +4 -4
- data/spec/rspec/matchers/throw_symbol_spec.rb +25 -25
- metadata +28 -40
@@ -11,11 +11,11 @@ describe "should change(actual, message)" do
|
|
11
11
|
@instance.some_value = 5
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "passes when actual is modified by the block" do
|
15
15
|
expect {@instance.some_value = 6}.to change(@instance, :some_value)
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "fails when actual is not modified by the block" do
|
19
19
|
expect do
|
20
20
|
expect {}.to change(@instance, :some_value)
|
21
21
|
end.to fail_with("some_value should have changed, but is still 5")
|
@@ -32,11 +32,11 @@ describe "should_not change(actual, message)" do
|
|
32
32
|
@instance.some_value = 5
|
33
33
|
end
|
34
34
|
|
35
|
-
it "
|
35
|
+
it "passes when actual is not modified by the block" do
|
36
36
|
expect { }.to_not change(@instance, :some_value)
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "fails when actual is not modified by the block" do
|
40
40
|
expect do
|
41
41
|
expect {@instance.some_value = 6}.to_not change(@instance, :some_value)
|
42
42
|
end.to fail_with("some_value should not have changed, but did change from 5 to 6")
|
@@ -49,17 +49,17 @@ describe "should change { block }" do
|
|
49
49
|
@instance.some_value = 5
|
50
50
|
end
|
51
51
|
|
52
|
-
it "
|
52
|
+
it "passes when actual is modified by the block" do
|
53
53
|
expect {@instance.some_value = 6}.to change { @instance.some_value }
|
54
54
|
end
|
55
55
|
|
56
|
-
it "
|
56
|
+
it "fails when actual is not modified by the block" do
|
57
57
|
expect do
|
58
58
|
expect {}.to change{ @instance.some_value }
|
59
59
|
end.to fail_with("result should have changed, but is still 5")
|
60
60
|
end
|
61
61
|
|
62
|
-
it "
|
62
|
+
it "warns if passed a block using do/end instead of {}" do
|
63
63
|
expect do
|
64
64
|
expect {}.to change do; end
|
65
65
|
end.to raise_error(RSpec::Matchers::MatcherError, /block passed to should or should_not/)
|
@@ -76,17 +76,17 @@ describe "should_not change { block }" do
|
|
76
76
|
@instance.some_value = 5
|
77
77
|
end
|
78
78
|
|
79
|
-
it "
|
79
|
+
it "passes when actual is modified by the block" do
|
80
80
|
expect {}.to_not change{ @instance.some_value }
|
81
81
|
end
|
82
82
|
|
83
|
-
it "
|
83
|
+
it "fails when actual is not modified by the block" do
|
84
84
|
expect do
|
85
85
|
expect {@instance.some_value = 6}.to_not change { @instance.some_value }
|
86
86
|
end.to fail_with("result should not have changed, but did change from 5 to 6")
|
87
87
|
end
|
88
88
|
|
89
|
-
it "
|
89
|
+
it "warns if passed a block using do/end instead of {}" do
|
90
90
|
expect do
|
91
91
|
expect {}.to_not change do; end
|
92
92
|
end.to raise_error(RSpec::Matchers::MatcherError, /block passed to should or should_not/)
|
@@ -99,17 +99,17 @@ describe "should change(actual, message).by(expected)" do
|
|
99
99
|
@instance.some_value = 5
|
100
100
|
end
|
101
101
|
|
102
|
-
it "
|
102
|
+
it "passes when attribute is changed by expected amount" do
|
103
103
|
expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1)
|
104
104
|
end
|
105
105
|
|
106
|
-
it "
|
106
|
+
it "fails when the attribute is changed by unexpected amount" do
|
107
107
|
expect do
|
108
108
|
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1)
|
109
109
|
end.to fail_with("some_value should have been changed by 1, but was changed by 2")
|
110
110
|
end
|
111
111
|
|
112
|
-
it "
|
112
|
+
it "fails when the attribute is changed by unexpected amount in the opposite direction" do
|
113
113
|
expect do
|
114
114
|
expect { @instance.some_value -= 1 }.to change(@instance, :some_value).by(1)
|
115
115
|
end.to fail_with("some_value should have been changed by 1, but was changed by -1")
|
@@ -122,17 +122,17 @@ describe "should change{ block }.by(expected)" do
|
|
122
122
|
@instance.some_value = 5
|
123
123
|
end
|
124
124
|
|
125
|
-
it "
|
125
|
+
it "passes when attribute is changed by expected amount" do
|
126
126
|
expect { @instance.some_value += 1 }.to change{@instance.some_value}.by(1)
|
127
127
|
end
|
128
128
|
|
129
|
-
it "
|
129
|
+
it "fails when the attribute is changed by unexpected amount" do
|
130
130
|
expect do
|
131
131
|
expect { @instance.some_value += 2 }.to change{@instance.some_value}.by(1)
|
132
132
|
end.to fail_with("result should have been changed by 1, but was changed by 2")
|
133
133
|
end
|
134
134
|
|
135
|
-
it "
|
135
|
+
it "fails when the attribute is changed by unexpected amount in the opposite direction" do
|
136
136
|
expect do
|
137
137
|
expect { @instance.some_value -= 1 }.to change{@instance.some_value}.by(1)
|
138
138
|
end.to fail_with("result should have been changed by 1, but was changed by -1")
|
@@ -145,15 +145,15 @@ describe "should change(actual, message).by_at_least(expected)" do
|
|
145
145
|
@instance.some_value = 5
|
146
146
|
end
|
147
147
|
|
148
|
-
it "
|
148
|
+
it "passes when attribute is changed by greater than the expected amount" do
|
149
149
|
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_least(1)
|
150
150
|
end
|
151
151
|
|
152
|
-
it "
|
152
|
+
it "passes when attribute is changed by the expected amount" do
|
153
153
|
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_least(2)
|
154
154
|
end
|
155
155
|
|
156
|
-
it "
|
156
|
+
it "fails when the attribute is changed by less than the expected amount" do
|
157
157
|
expect do
|
158
158
|
expect { @instance.some_value += 1 }.to change(@instance, :some_value).by_at_least(2)
|
159
159
|
end.to fail_with("some_value should have been changed by at least 2, but was changed by 1")
|
@@ -167,15 +167,15 @@ describe "should change{ block }.by_at_least(expected)" do
|
|
167
167
|
@instance.some_value = 5
|
168
168
|
end
|
169
169
|
|
170
|
-
it "
|
170
|
+
it "passes when attribute is changed by greater than expected amount" do
|
171
171
|
expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_least(1)
|
172
172
|
end
|
173
173
|
|
174
|
-
it "
|
174
|
+
it "passes when attribute is changed by the expected amount" do
|
175
175
|
expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_least(2)
|
176
176
|
end
|
177
177
|
|
178
|
-
it "
|
178
|
+
it "fails when the attribute is changed by less than the unexpected amount" do
|
179
179
|
expect do
|
180
180
|
expect { @instance.some_value += 1 }.to change{@instance.some_value}.by_at_least(2)
|
181
181
|
end.to fail_with("result should have been changed by at least 2, but was changed by 1")
|
@@ -189,15 +189,15 @@ describe "should change(actual, message).by_at_most(expected)" do
|
|
189
189
|
@instance.some_value = 5
|
190
190
|
end
|
191
191
|
|
192
|
-
it "
|
192
|
+
it "passes when attribute is changed by less than the expected amount" do
|
193
193
|
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_most(3)
|
194
194
|
end
|
195
195
|
|
196
|
-
it "
|
196
|
+
it "passes when attribute is changed by the expected amount" do
|
197
197
|
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_most(2)
|
198
198
|
end
|
199
199
|
|
200
|
-
it "
|
200
|
+
it "fails when the attribute is changed by greater than the expected amount" do
|
201
201
|
expect do
|
202
202
|
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_most(1)
|
203
203
|
end.to fail_with("some_value should have been changed by at most 1, but was changed by 2")
|
@@ -211,15 +211,15 @@ describe "should change{ block }.by_at_most(expected)" do
|
|
211
211
|
@instance.some_value = 5
|
212
212
|
end
|
213
213
|
|
214
|
-
it "
|
214
|
+
it "passes when attribute is changed by less than expected amount" do
|
215
215
|
expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_most(3)
|
216
216
|
end
|
217
217
|
|
218
|
-
it "
|
218
|
+
it "passes when attribute is changed by the expected amount" do
|
219
219
|
expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_most(2)
|
220
220
|
end
|
221
221
|
|
222
|
-
it "
|
222
|
+
it "fails when the attribute is changed by greater than the unexpected amount" do
|
223
223
|
expect do
|
224
224
|
expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_most(1)
|
225
225
|
end.to fail_with("result should have been changed by at most 1, but was changed by 2")
|
@@ -232,11 +232,11 @@ describe "should change(actual, message).from(old)" do
|
|
232
232
|
@instance.some_value = 'string'
|
233
233
|
end
|
234
234
|
|
235
|
-
it "
|
235
|
+
it "passes when attribute is == to expected value before executing block" do
|
236
236
|
expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from("string")
|
237
237
|
end
|
238
238
|
|
239
|
-
it "
|
239
|
+
it "fails when attribute is not == to expected value before executing block" do
|
240
240
|
expect do
|
241
241
|
expect { @instance.some_value = "knot" }.to change(@instance, :some_value).from("cat")
|
242
242
|
end.to fail_with("some_value should have initially been \"cat\", but was \"string\"")
|
@@ -249,11 +249,11 @@ describe "should change{ block }.from(old)" do
|
|
249
249
|
@instance.some_value = 'string'
|
250
250
|
end
|
251
251
|
|
252
|
-
it "
|
252
|
+
it "passes when attribute is == to expected value before executing block" do
|
253
253
|
expect { @instance.some_value = "astring" }.to change{@instance.some_value}.from("string")
|
254
254
|
end
|
255
255
|
|
256
|
-
it "
|
256
|
+
it "fails when attribute is not == to expected value before executing block" do
|
257
257
|
expect do
|
258
258
|
expect { @instance.some_value = "knot" }.to change{@instance.some_value}.from("cat")
|
259
259
|
end.to fail_with("result should have initially been \"cat\", but was \"string\"")
|
@@ -266,11 +266,11 @@ describe "should change(actual, message).to(new)" do
|
|
266
266
|
@instance.some_value = 'string'
|
267
267
|
end
|
268
268
|
|
269
|
-
it "
|
269
|
+
it "passes when attribute is == to expected value after executing block" do
|
270
270
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat")
|
271
271
|
end
|
272
272
|
|
273
|
-
it "
|
273
|
+
it "fails when attribute is not == to expected value after executing block" do
|
274
274
|
expect do
|
275
275
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
|
276
276
|
end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
|
@@ -283,11 +283,11 @@ describe "should change{ block }.to(new)" do
|
|
283
283
|
@instance.some_value = 'string'
|
284
284
|
end
|
285
285
|
|
286
|
-
it "
|
286
|
+
it "passes when attribute is == to expected value after executing block" do
|
287
287
|
expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to("cat")
|
288
288
|
end
|
289
289
|
|
290
|
-
it "
|
290
|
+
it "fails when attribute is not == to expected value after executing block" do
|
291
291
|
expect do
|
292
292
|
expect { @instance.some_value = "cat" }.to change{@instance.some_value}.from("string").to("dog")
|
293
293
|
end.to fail_with("result should have been changed to \"dog\", but is now \"cat\"")
|
@@ -300,21 +300,21 @@ describe "should change(actual, message).from(old).to(new)" do
|
|
300
300
|
@instance.some_value = 'string'
|
301
301
|
end
|
302
302
|
|
303
|
-
it "
|
303
|
+
it "passes when #to comes before #from" do
|
304
304
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat").from("string")
|
305
305
|
end
|
306
306
|
|
307
|
-
it "
|
307
|
+
it "passes when #from comes before #to" do
|
308
308
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("cat")
|
309
309
|
end
|
310
310
|
|
311
|
-
it "
|
311
|
+
it "shows the correct messaging when #after and #to are different" do
|
312
312
|
expect do
|
313
313
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
|
314
314
|
end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
|
315
315
|
end
|
316
316
|
|
317
|
-
it "
|
317
|
+
it "shows the correct messaging when #before and #from are different" do
|
318
318
|
expect do
|
319
319
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("not_string").to("cat")
|
320
320
|
end.to fail_with("some_value should have initially been \"not_string\", but was \"string\"")
|
@@ -327,17 +327,17 @@ describe "should change{ block }.from(old).to(new)" do
|
|
327
327
|
@instance.some_value = 'string'
|
328
328
|
end
|
329
329
|
|
330
|
-
it "
|
330
|
+
it "passes when #to comes before #from" do
|
331
331
|
expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to("cat").from("string")
|
332
332
|
end
|
333
333
|
|
334
|
-
it "
|
334
|
+
it "passes when #from comes before #to" do
|
335
335
|
expect { @instance.some_value = "cat" }.to change{@instance.some_value}.from("string").to("cat")
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
339
|
describe RSpec::Matchers::Change do
|
340
|
-
it "
|
340
|
+
it "works when the receiver has implemented #send" do
|
341
341
|
@instance = SomethingExpected.new
|
342
342
|
@instance.some_value = "string"
|
343
343
|
def @instance.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
@@ -153,7 +153,7 @@ describe "a Matcher with no description" do
|
|
153
153
|
end.new
|
154
154
|
end
|
155
155
|
|
156
|
-
it "
|
156
|
+
it "provides a helpful message when used in a string-less example block" do
|
157
157
|
5.should matcher
|
158
158
|
RSpec::Matchers.generated_description.should =~ /When you call.*description method/m
|
159
159
|
end
|
@@ -3,27 +3,27 @@ require 'spec_helper'
|
|
3
3
|
module RSpec
|
4
4
|
module Matchers
|
5
5
|
describe "eql" do
|
6
|
-
it "
|
6
|
+
it "matches when actual.eql?(expected)" do
|
7
7
|
1.should eql(1)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
10
|
+
it "does not match when !actual.eql?(expected)" do
|
11
11
|
1.should_not eql(2)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "describes itself" do
|
15
15
|
matcher = eql(1)
|
16
16
|
matcher.matches?(1)
|
17
17
|
matcher.description.should == "eql 1"
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "provides message, expected and actual on #failure_message" do
|
21
21
|
matcher = eql("1")
|
22
22
|
matcher.matches?(1)
|
23
23
|
matcher.failure_message_for_should.should == "\nexpected \"1\"\n got 1\n\n(compared using eql?)\n"
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "provides message, expected and actual on #negative_failure_message" do
|
27
27
|
matcher = eql(1)
|
28
28
|
matcher.matches?(1)
|
29
29
|
matcher.failure_message_for_should_not.should == "\nexpected 1 not to equal 1\n\n(compared using eql?)\n"
|
@@ -7,21 +7,21 @@ module RSpec
|
|
7
7
|
"#<#{o.class}:#{o.object_id}> => #{o.inspect}"
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
10
|
+
it "matches when actual.equal?(expected)" do
|
11
11
|
1.should equal(1)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "does not match when !actual.equal?(expected)" do
|
15
15
|
1.should_not equal("1")
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "describes itself" do
|
19
19
|
matcher = equal(1)
|
20
20
|
matcher.matches?(1)
|
21
21
|
matcher.description.should == "equal 1"
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "provides message on #failure_message" do
|
25
25
|
expected, actual = "1", "1"
|
26
26
|
matcher = equal(expected)
|
27
27
|
matcher.matches?(actual)
|
@@ -39,7 +39,7 @@ object identity in this example.
|
|
39
39
|
MESSAGE
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "provides message on #negative_failure_message" do
|
43
43
|
expected = actual = "1"
|
44
44
|
matcher = equal(expected)
|
45
45
|
matcher.matches?(actual)
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "should have_sym(*args)" do
|
4
|
-
it "
|
4
|
+
it "passes if #has_sym?(*args) returns true" do
|
5
5
|
{:a => "A"}.should have_key(:a)
|
6
6
|
end
|
7
7
|
|
8
|
-
it "
|
8
|
+
it "fails if #has_sym?(*args) returns false" do
|
9
9
|
lambda {
|
10
10
|
{:b => "B"}.should have_key(:a)
|
11
11
|
}.should fail_with("expected #has_key?(:a) to return true, got false")
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "fails if #has_sym?(*args) returns nil" do
|
15
15
|
klass = Class.new do
|
16
16
|
def has_foo?
|
17
17
|
end
|
@@ -21,13 +21,13 @@ describe "should have_sym(*args)" do
|
|
21
21
|
}.should fail_with("expected #has_foo?(nil) to return true, got false")
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "fails if target does not respond to #has_sym?" do
|
25
25
|
lambda {
|
26
26
|
Object.new.should have_key(:a)
|
27
27
|
}.should raise_error(NoMethodError)
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
30
|
+
it "reraises an exception thrown in #has_sym?(*args)" do
|
31
31
|
o = Object.new
|
32
32
|
def o.has_sym?(*args)
|
33
33
|
raise "Funky exception"
|
@@ -37,11 +37,11 @@ describe "should have_sym(*args)" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "should_not have_sym(*args)" do
|
40
|
-
it "
|
40
|
+
it "passes if #has_sym?(*args) returns false" do
|
41
41
|
{:a => "A"}.should_not have_key(:b)
|
42
42
|
end
|
43
43
|
|
44
|
-
it "
|
44
|
+
it "passes if #has_sym?(*args) returns nil" do
|
45
45
|
klass = Class.new do
|
46
46
|
def has_foo?
|
47
47
|
end
|
@@ -49,19 +49,19 @@ describe "should_not have_sym(*args)" do
|
|
49
49
|
klass.new.should_not have_foo
|
50
50
|
end
|
51
51
|
|
52
|
-
it "
|
52
|
+
it "fails if #has_sym?(*args) returns true" do
|
53
53
|
lambda {
|
54
54
|
{:a => "A"}.should_not have_key(:a)
|
55
55
|
}.should fail_with("expected #has_key?(:a) to return false, got true")
|
56
56
|
end
|
57
57
|
|
58
|
-
it "
|
58
|
+
it "fails if target does not respond to #has_sym?" do
|
59
59
|
lambda {
|
60
60
|
Object.new.should have_key(:a)
|
61
61
|
}.should raise_error(NoMethodError)
|
62
62
|
end
|
63
63
|
|
64
|
-
it "
|
64
|
+
it "reraises an exception thrown in #has_sym?(*args)" do
|
65
65
|
o = Object.new
|
66
66
|
def o.has_sym?(*args)
|
67
67
|
raise "Funky exception"
|
@@ -71,7 +71,7 @@ describe "should_not have_sym(*args)" do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "has" do
|
74
|
-
it "
|
74
|
+
it "works when the target implements #send" do
|
75
75
|
o = {:a => "A"}
|
76
76
|
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
77
77
|
lambda {
|