rspec-mocks 2.12.1 → 2.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +17 -0
- data/lib/rspec/mocks.rb +8 -0
- data/lib/rspec/mocks/message_expectation.rb +6 -11
- data/lib/rspec/mocks/method_double.rb +19 -2
- data/lib/rspec/mocks/mutate_const.rb +1 -1
- data/lib/rspec/mocks/proxy.rb +1 -1
- data/lib/rspec/mocks/version.rb +1 -1
- data/lib/spec/mocks.rb +4 -0
- data/spec/rspec/mocks/and_call_original_spec.rb +22 -0
- data/spec/rspec/mocks/and_yield_spec.rb +7 -7
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +6 -6
- data/spec/rspec/mocks/any_instance_spec.rb +94 -94
- data/spec/rspec/mocks/any_number_of_times_spec.rb +2 -2
- data/spec/rspec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/rspec/mocks/at_least_spec.rb +15 -15
- data/spec/rspec/mocks/at_most_spec.rb +7 -7
- data/spec/rspec/mocks/block_return_value_spec.rb +6 -6
- data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_10263_spec.rb +6 -4
- data/spec/rspec/mocks/bug_report_11545_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_600_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_7611_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_8165_spec.rb +4 -4
- data/spec/rspec/mocks/bug_report_830_spec.rb +2 -2
- data/spec/rspec/mocks/bug_report_957_spec.rb +2 -2
- data/spec/rspec/mocks/configuration_spec.rb +4 -4
- data/spec/rspec/mocks/double_spec.rb +1 -1
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +1 -1
- data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +13 -13
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +30 -30
- data/spec/rspec/mocks/mock_ordering_spec.rb +8 -8
- data/spec/rspec/mocks/mock_space_spec.rb +4 -4
- data/spec/rspec/mocks/mock_spec.rb +94 -90
- data/spec/rspec/mocks/multiple_return_value_spec.rb +21 -21
- data/spec/rspec/mocks/mutate_const_spec.rb +112 -102
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +6 -12
- data/spec/rspec/mocks/null_object_mock_spec.rb +12 -12
- data/spec/rspec/mocks/once_counts_spec.rb +7 -7
- data/spec/rspec/mocks/options_hash_spec.rb +6 -6
- data/spec/rspec/mocks/partial_mock_spec.rb +15 -15
- data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +17 -17
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +6 -6
- data/spec/rspec/mocks/precise_counts_spec.rb +7 -7
- data/spec/rspec/mocks/record_messages_spec.rb +4 -4
- data/spec/rspec/mocks/serialization_spec.rb +3 -3
- data/spec/rspec/mocks/stash_spec.rb +1 -1
- data/spec/rspec/mocks/stub_chain_spec.rb +22 -22
- data/spec/rspec/mocks/stub_implementation_spec.rb +10 -10
- data/spec/rspec/mocks/stub_spec.rb +50 -31
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +3 -3
- data/spec/rspec/mocks/test_double_spec.rb +3 -3
- data/spec/rspec/mocks/to_ary_spec.rb +7 -7
- data/spec/rspec/mocks/twice_counts_spec.rb +8 -8
- data/spec/rspec/mocks_spec.rb +13 -4
- data/spec/spec_helper.rb +4 -0
- metadata +5 -5
@@ -30,9 +30,9 @@ module RSpec
|
|
30
30
|
it "fails when messages are received out of order (2nd message 1st)" do
|
31
31
|
@double.should_receive(:one).ordered
|
32
32
|
@double.should_receive(:two).ordered
|
33
|
-
|
33
|
+
expect {
|
34
34
|
@double.two
|
35
|
-
|
35
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :two out of order")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "fails when messages are received out of order (3rd message 1st)" do
|
@@ -40,9 +40,9 @@ module RSpec
|
|
40
40
|
@double.should_receive(:two).ordered
|
41
41
|
@double.should_receive(:three).ordered
|
42
42
|
@double.one
|
43
|
-
|
43
|
+
expect {
|
44
44
|
@double.three
|
45
|
-
|
45
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
46
46
|
end
|
47
47
|
|
48
48
|
it "fails when messages are received out of order (3rd message 2nd)" do
|
@@ -50,9 +50,9 @@ module RSpec
|
|
50
50
|
@double.should_receive(:two).ordered
|
51
51
|
@double.should_receive(:three).ordered
|
52
52
|
@double.one
|
53
|
-
|
53
|
+
expect {
|
54
54
|
@double.three
|
55
|
-
|
55
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
56
56
|
end
|
57
57
|
|
58
58
|
it "fails when messages are out of order across objects" do
|
@@ -62,9 +62,9 @@ module RSpec
|
|
62
62
|
b.should_receive(:two).ordered
|
63
63
|
a.should_receive(:three).ordered
|
64
64
|
a.one
|
65
|
-
|
65
|
+
expect {
|
66
66
|
a.three
|
67
|
-
|
67
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
68
68
|
a.rspec_reset
|
69
69
|
b.rspec_reset
|
70
70
|
end
|
@@ -27,8 +27,8 @@ module RSpec
|
|
27
27
|
@space.add(@m1)
|
28
28
|
@space.add(@m2)
|
29
29
|
@space.verify_all
|
30
|
-
@m1.
|
31
|
-
@m2.
|
30
|
+
expect(@m1).to be_verified
|
31
|
+
expect(@m2).to be_verified
|
32
32
|
end
|
33
33
|
it "resets all mocks within" do
|
34
34
|
@space.add(m1 = double("mock1"))
|
@@ -40,11 +40,11 @@ module RSpec
|
|
40
40
|
it "clears internal mocks on reset_all" do
|
41
41
|
@space.add(double("mock"))
|
42
42
|
@space.reset_all
|
43
|
-
@space.instance_eval { receivers.empty? }.
|
43
|
+
expect(@space.instance_eval { receivers.empty? }).to be_true
|
44
44
|
end
|
45
45
|
it "resets the ordering" do
|
46
46
|
@space.reset_all
|
47
|
-
@space.expectation_ordering.
|
47
|
+
expect(@space.expectation_ordering).to be_empty
|
48
48
|
end
|
49
49
|
it "only adds an instance once" do
|
50
50
|
@space.add(m1 = double("mock1"))
|
@@ -7,11 +7,11 @@ module RSpec
|
|
7
7
|
after(:each) { @double.rspec_reset }
|
8
8
|
|
9
9
|
it "has method_missing as private" do
|
10
|
-
RSpec::Mocks::Mock.private_instance_methods.
|
10
|
+
expect(RSpec::Mocks::Mock.private_instance_methods).to include_method(:method_missing)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "does not respond_to? method_missing (because it's private)" do
|
14
|
-
RSpec::Mocks::Mock.new.
|
14
|
+
expect(RSpec::Mocks::Mock.new).not_to respond_to(:method_missing)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "reports line number of expectation of unreceived message" do
|
@@ -21,7 +21,7 @@ module RSpec
|
|
21
21
|
violated
|
22
22
|
rescue RSpec::Mocks::MockExpectationError => e
|
23
23
|
# NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
|
24
|
-
e.backtrace[0].
|
24
|
+
expect(e.backtrace[0]).to match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -33,7 +33,7 @@ module RSpec
|
|
33
33
|
violated
|
34
34
|
rescue RSpec::Mocks::MockExpectationError => e
|
35
35
|
# NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
|
36
|
-
e.backtrace[0].
|
36
|
+
expect(e.backtrace[0]).to match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -43,7 +43,7 @@ module RSpec
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "warns when should_not_receive is followed by and_return" do
|
46
|
-
RSpec.should_receive(:warn_deprecation).
|
46
|
+
RSpec::Mocks.should_receive(:warn_deprecation).
|
47
47
|
with(/`and_return` with `should_not_receive` is deprecated/)
|
48
48
|
|
49
49
|
@double.should_not_receive(:do_something).and_return(1)
|
@@ -86,64 +86,64 @@ module RSpec
|
|
86
86
|
|
87
87
|
it "allows block to calculate return values" do
|
88
88
|
@double.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
|
89
|
-
@double.something("a","b","c").
|
89
|
+
expect(@double.something("a","b","c")).to eq "cba"
|
90
90
|
@double.rspec_verify
|
91
91
|
end
|
92
92
|
|
93
93
|
it "allows parameter as return value" do
|
94
94
|
@double.should_receive(:something).with("a","b","c").and_return("booh")
|
95
|
-
@double.something("a","b","c").
|
95
|
+
expect(@double.something("a","b","c")).to eq "booh"
|
96
96
|
@double.rspec_verify
|
97
97
|
end
|
98
98
|
|
99
99
|
it "returns the previously stubbed value if no return value is set" do
|
100
100
|
@double.stub(:something).with("a","b","c").and_return(:stubbed_value)
|
101
101
|
@double.should_receive(:something).with("a","b","c")
|
102
|
-
@double.something("a","b","c").
|
102
|
+
expect(@double.something("a","b","c")).to eq :stubbed_value
|
103
103
|
@double.rspec_verify
|
104
104
|
end
|
105
105
|
|
106
106
|
it "returns nil if no return value is set and there is no previously stubbed value" do
|
107
107
|
@double.should_receive(:something).with("a","b","c")
|
108
|
-
@double.something("a","b","c").
|
108
|
+
expect(@double.something("a","b","c")).to be_nil
|
109
109
|
@double.rspec_verify
|
110
110
|
end
|
111
111
|
|
112
112
|
it "raises exception if args don't match when method called" do
|
113
113
|
@double.should_receive(:something).with("a","b","c").and_return("booh")
|
114
|
-
|
114
|
+
expect {
|
115
115
|
@double.something("a","d","c")
|
116
116
|
violated
|
117
|
-
}.
|
117
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
|
118
118
|
end
|
119
119
|
|
120
120
|
describe "even when a similar expectation with different arguments exist" do
|
121
121
|
it "raises exception if args don't match when method called, correctly reporting the offending arguments" do
|
122
122
|
@double.should_receive(:something).with("a","b","c").once
|
123
123
|
@double.should_receive(:something).with("z","x","c").once
|
124
|
-
|
124
|
+
expect {
|
125
125
|
@double.something("a","b","c")
|
126
126
|
@double.something("z","x","g")
|
127
|
-
}.
|
127
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"z\", \"x\", \"c\")\n got: (\"z\", \"x\", \"g\")")
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
it "raises exception if args don't match when method called even when the method is stubbed" do
|
132
132
|
@double.stub(:something)
|
133
133
|
@double.should_receive(:something).with("a","b","c")
|
134
|
-
|
134
|
+
expect {
|
135
135
|
@double.something("a","d","c")
|
136
136
|
@double.rspec_verify
|
137
|
-
}.
|
137
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
|
138
138
|
end
|
139
139
|
|
140
140
|
it "raises exception if args don't match when method called even when using null_object" do
|
141
141
|
@double = double("test double").as_null_object
|
142
142
|
@double.should_receive(:something).with("a","b","c")
|
143
|
-
|
143
|
+
expect {
|
144
144
|
@double.something("a","d","c")
|
145
145
|
@double.rspec_verify
|
146
|
-
}.
|
146
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
|
147
147
|
end
|
148
148
|
|
149
149
|
describe 'with a method that has a default argument' do
|
@@ -159,24 +159,27 @@ module RSpec
|
|
159
159
|
end
|
160
160
|
|
161
161
|
it "fails if unexpected method called" do
|
162
|
-
|
162
|
+
expect {
|
163
163
|
@double.something("a","b","c")
|
164
164
|
violated
|
165
|
-
}.
|
165
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received unexpected message :something with (\"a\", \"b\", \"c\")")
|
166
166
|
end
|
167
167
|
|
168
168
|
it "uses block for expectation if provided" do
|
169
169
|
@double.should_receive(:something) do | a, b |
|
170
|
-
a.
|
171
|
-
b.
|
170
|
+
expect(a).to eq "a"
|
171
|
+
expect(b).to eq "b"
|
172
172
|
"booh"
|
173
173
|
end
|
174
|
-
@double.something("a", "b").
|
174
|
+
expect(@double.something("a", "b")).to eq "booh"
|
175
175
|
@double.rspec_verify
|
176
176
|
end
|
177
177
|
|
178
178
|
it "fails if expectation block fails" do
|
179
|
-
@double.should_receive(:something)
|
179
|
+
@double.should_receive(:something) do |bool|
|
180
|
+
expect(bool).to be_true
|
181
|
+
end
|
182
|
+
|
180
183
|
expect {
|
181
184
|
@double.something false
|
182
185
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
@@ -186,22 +189,22 @@ module RSpec
|
|
186
189
|
it "passes proc to expectation block without an argument" do
|
187
190
|
# We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }
|
188
191
|
# and prevents the entire spec suite from running.
|
189
|
-
eval("@double.should_receive(:foo) {|&block| block.call.
|
192
|
+
eval("@double.should_receive(:foo) {|&block| expect(block.call).to eq(:bar)}")
|
190
193
|
@double.foo { :bar }
|
191
194
|
end
|
192
195
|
|
193
196
|
it "passes proc to expectation block with an argument" do
|
194
|
-
eval("@double.should_receive(:foo) {|arg, &block| block.call.
|
197
|
+
eval("@double.should_receive(:foo) {|arg, &block| expect(block.call).to eq(:bar)}")
|
195
198
|
@double.foo(:arg) { :bar }
|
196
199
|
end
|
197
200
|
|
198
201
|
it "passes proc to stub block without an argurment" do
|
199
|
-
eval("@double.stub(:foo) {|&block| block.call.
|
202
|
+
eval("@double.stub(:foo) {|&block| expect(block.call).to eq(:bar)}")
|
200
203
|
@double.foo { :bar }
|
201
204
|
end
|
202
205
|
|
203
206
|
it "passes proc to stub block with an argument" do
|
204
|
-
eval("@double.stub(:foo) {|arg, &block| block.call.
|
207
|
+
eval("@double.stub(:foo) {|arg, &block| expect(block.call).to eq(:bar)}")
|
205
208
|
@double.foo(:arg) { :bar }
|
206
209
|
end
|
207
210
|
end
|
@@ -254,23 +257,23 @@ module RSpec
|
|
254
257
|
@double.something
|
255
258
|
fail "OutOfGas was not raised"
|
256
259
|
rescue OutOfGas => e
|
257
|
-
e.amount.
|
258
|
-
e.units.
|
260
|
+
expect(e.amount).to eq 2
|
261
|
+
expect(e.units).to eq :oz
|
259
262
|
end
|
260
263
|
end
|
261
264
|
|
262
265
|
it "does not raise when told to if args dont match" do
|
263
266
|
@double.should_receive(:something).with(2).and_raise(RuntimeError)
|
264
|
-
|
267
|
+
expect {
|
265
268
|
@double.something 1
|
266
|
-
}.
|
269
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
267
270
|
end
|
268
271
|
|
269
272
|
it "throws when told to" do
|
270
273
|
@double.should_receive(:something).and_throw(:blech)
|
271
|
-
|
274
|
+
expect {
|
272
275
|
@double.something
|
273
|
-
}.
|
276
|
+
}.to throw_symbol(:blech)
|
274
277
|
end
|
275
278
|
|
276
279
|
it "ignores args on any args" do
|
@@ -284,21 +287,22 @@ module RSpec
|
|
284
287
|
|
285
288
|
it "fails on no args if any args received" do
|
286
289
|
@double.should_receive(:something).with(no_args())
|
287
|
-
|
290
|
+
expect {
|
288
291
|
@double.something 1
|
289
|
-
}.
|
292
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (no args)\n got: (1)")
|
290
293
|
end
|
291
294
|
|
292
295
|
it "fails when args are expected but none are received" do
|
293
296
|
@double.should_receive(:something).with(1)
|
294
|
-
|
297
|
+
expect {
|
295
298
|
@double.something
|
296
|
-
}.
|
299
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (1)\n got: (no args)")
|
297
300
|
end
|
298
301
|
|
299
302
|
it "returns value from block by default" do
|
300
303
|
@double.stub(:method_that_yields).and_yield
|
301
|
-
@double.method_that_yields { :returned_obj }
|
304
|
+
value = @double.method_that_yields { :returned_obj }
|
305
|
+
expect(value).to eq :returned_obj
|
302
306
|
@double.rspec_verify
|
303
307
|
end
|
304
308
|
|
@@ -306,7 +310,7 @@ module RSpec
|
|
306
310
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield
|
307
311
|
a = nil
|
308
312
|
@double.yield_back {|*x| a = x}
|
309
|
-
a.
|
313
|
+
expect(a).to eq []
|
310
314
|
@double.rspec_verify
|
311
315
|
end
|
312
316
|
|
@@ -315,7 +319,7 @@ module RSpec
|
|
315
319
|
and_yield
|
316
320
|
b = []
|
317
321
|
@double.yield_back {|*a| b << a}
|
318
|
-
b.
|
322
|
+
expect(b).to eq [ [], [] ]
|
319
323
|
@double.rspec_verify
|
320
324
|
end
|
321
325
|
|
@@ -323,7 +327,7 @@ module RSpec
|
|
323
327
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield(99)
|
324
328
|
a = nil
|
325
329
|
@double.yield_back {|*x| a = x}
|
326
|
-
a.
|
330
|
+
expect(a).to eq [99]
|
327
331
|
@double.rspec_verify
|
328
332
|
end
|
329
333
|
|
@@ -333,7 +337,7 @@ module RSpec
|
|
333
337
|
and_yield("something fruity")
|
334
338
|
b = []
|
335
339
|
@double.yield_back {|*a| b << a}
|
336
|
-
b.
|
340
|
+
expect(b).to eq [[99], [43], ["something fruity"]]
|
337
341
|
@double.rspec_verify
|
338
342
|
end
|
339
343
|
|
@@ -341,7 +345,7 @@ module RSpec
|
|
341
345
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go")
|
342
346
|
a = nil
|
343
347
|
@double.yield_back {|*x| a = x}
|
344
|
-
a.
|
348
|
+
expect(a).to eq [99, 27, "go"]
|
345
349
|
@double.rspec_verify
|
346
350
|
end
|
347
351
|
|
@@ -351,7 +355,7 @@ module RSpec
|
|
351
355
|
and_yield("stop", 12, :red)
|
352
356
|
b = []
|
353
357
|
@double.yield_back {|*a| b << a}
|
354
|
-
b.
|
358
|
+
expect(b).to eq [[99, :green, "go"], ["wait", :amber], ["stop", 12, :red]]
|
355
359
|
@double.rspec_verify
|
356
360
|
end
|
357
361
|
|
@@ -359,7 +363,7 @@ module RSpec
|
|
359
363
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield(99)
|
360
364
|
a = nil
|
361
365
|
@double.yield_back {|x| a = x}
|
362
|
-
a.
|
366
|
+
expect(a).to eq 99
|
363
367
|
@double.rspec_verify
|
364
368
|
end
|
365
369
|
|
@@ -369,7 +373,7 @@ module RSpec
|
|
369
373
|
and_yield("something fruity")
|
370
374
|
b = []
|
371
375
|
@double.yield_back {|a| b << a}
|
372
|
-
b.
|
376
|
+
expect(b).to eq [99, 43, "something fruity"]
|
373
377
|
@double.rspec_verify
|
374
378
|
end
|
375
379
|
|
@@ -377,8 +381,8 @@ module RSpec
|
|
377
381
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
|
378
382
|
a, b = nil
|
379
383
|
@double.yield_back {|x,y| a=x; b=y}
|
380
|
-
a.
|
381
|
-
b.
|
384
|
+
expect(a).to eq 'wha'
|
385
|
+
expect(b).to eq 'zup'
|
382
386
|
@double.rspec_verify
|
383
387
|
end
|
384
388
|
|
@@ -388,32 +392,32 @@ module RSpec
|
|
388
392
|
and_yield(14, 65)
|
389
393
|
c = []
|
390
394
|
@double.yield_back {|a,b| c << [a, b]}
|
391
|
-
c.
|
395
|
+
expect(c).to eq [['wha', 'zup'], ['not', 'down'], [14, 65]]
|
392
396
|
@double.rspec_verify
|
393
397
|
end
|
394
398
|
|
395
399
|
it "fails when calling yielding method with wrong arity" do
|
396
400
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
|
397
|
-
|
401
|
+
expect {
|
398
402
|
@double.yield_back {|a|}
|
399
|
-
}.
|
403
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" yielded |\"wha\", \"zup\"| to block with arity of 1")
|
400
404
|
end
|
401
405
|
|
402
406
|
it "fails when calling yielding method consecutively with wrong arity" do
|
403
407
|
@double.should_receive(:yield_back).once.with(no_args()).once.and_yield('wha', 'zup').
|
404
408
|
and_yield('down').
|
405
409
|
and_yield(14, 65)
|
406
|
-
|
410
|
+
expect {
|
407
411
|
c = []
|
408
412
|
@double.yield_back {|a,b| c << [a, b]}
|
409
|
-
}.
|
413
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" yielded |\"down\"| to block with arity of 2")
|
410
414
|
end
|
411
415
|
|
412
416
|
it "fails when calling yielding method without block" do
|
413
417
|
@double.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
|
414
|
-
|
418
|
+
expect {
|
415
419
|
@double.yield_back
|
416
|
-
}.
|
420
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" asked to yield |[\"wha\", \"zup\"]| but no block was passed")
|
417
421
|
end
|
418
422
|
|
419
423
|
it "is able to double send" do
|
@@ -425,11 +429,11 @@ module RSpec
|
|
425
429
|
it "is able to raise from method calling yielding double" do
|
426
430
|
@double.should_receive(:yield_me).and_yield 44
|
427
431
|
|
428
|
-
|
432
|
+
expect {
|
429
433
|
@double.yield_me do |x|
|
430
434
|
raise "Bang"
|
431
435
|
end
|
432
|
-
}.
|
436
|
+
}.to raise_error(StandardError, "Bang")
|
433
437
|
|
434
438
|
@double.rspec_verify
|
435
439
|
end
|
@@ -438,9 +442,9 @@ module RSpec
|
|
438
442
|
@double.should_receive(:foobar)
|
439
443
|
@double.foobar
|
440
444
|
@double.rspec_verify
|
441
|
-
|
445
|
+
expect {
|
442
446
|
@double.foobar
|
443
|
-
}.
|
447
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, %q|Double "test double" received unexpected message :foobar with (no args)|)
|
444
448
|
end
|
445
449
|
|
446
450
|
it "restores objects to their original state on rspec_reset" do
|
@@ -475,25 +479,25 @@ module RSpec
|
|
475
479
|
@double.foobar
|
476
480
|
@double.rspec_verify
|
477
481
|
|
478
|
-
|
479
|
-
|
482
|
+
expect { @double.foobar }.to_not raise_error(NameError)
|
483
|
+
expect { @double.foobar }.to raise_error(RSpec::Mocks::MockExpectationError)
|
480
484
|
end
|
481
485
|
|
482
486
|
it "temporarily replaces a method stub on a double" do
|
483
487
|
@double.stub(:msg).and_return(:stub_value)
|
484
488
|
@double.should_receive(:msg).with(:arg).and_return(:double_value)
|
485
|
-
@double.msg(:arg).
|
486
|
-
@double.msg.
|
487
|
-
@double.msg.
|
489
|
+
expect(@double.msg(:arg)).to equal(:double_value)
|
490
|
+
expect(@double.msg).to equal(:stub_value)
|
491
|
+
expect(@double.msg).to equal(:stub_value)
|
488
492
|
@double.rspec_verify
|
489
493
|
end
|
490
494
|
|
491
495
|
it "does not require a different signature to replace a method stub" do
|
492
496
|
@double.stub(:msg).and_return(:stub_value)
|
493
497
|
@double.should_receive(:msg).and_return(:double_value)
|
494
|
-
@double.msg(:arg).
|
495
|
-
@double.msg.
|
496
|
-
@double.msg.
|
498
|
+
expect(@double.msg(:arg)).to equal(:double_value)
|
499
|
+
expect(@double.msg).to equal(:stub_value)
|
500
|
+
expect(@double.msg).to equal(:stub_value)
|
497
501
|
@double.rspec_verify
|
498
502
|
end
|
499
503
|
|
@@ -507,31 +511,31 @@ module RSpec
|
|
507
511
|
non_double = Object.new
|
508
512
|
non_double.stub(:msg).and_return(:stub_value)
|
509
513
|
non_double.should_receive(:msg).with(:arg).and_return(:double_value)
|
510
|
-
non_double.msg(:arg).
|
511
|
-
non_double.msg.
|
512
|
-
non_double.msg.
|
514
|
+
expect(non_double.msg(:arg)).to equal(:double_value)
|
515
|
+
expect(non_double.msg).to equal(:stub_value)
|
516
|
+
expect(non_double.msg).to equal(:stub_value)
|
513
517
|
non_double.rspec_verify
|
514
518
|
end
|
515
519
|
|
516
520
|
it "returns the stubbed value when no new value specified" do
|
517
521
|
@double.stub(:msg).and_return(:stub_value)
|
518
522
|
@double.should_receive(:msg)
|
519
|
-
@double.msg.
|
523
|
+
expect(@double.msg).to equal(:stub_value)
|
520
524
|
@double.rspec_verify
|
521
525
|
end
|
522
526
|
|
523
527
|
it "returns the stubbed value when stubbed with args and no new value specified" do
|
524
528
|
@double.stub(:msg).with(:arg).and_return(:stub_value)
|
525
529
|
@double.should_receive(:msg).with(:arg)
|
526
|
-
@double.msg(:arg).
|
530
|
+
expect(@double.msg(:arg)).to equal(:stub_value)
|
527
531
|
@double.rspec_verify
|
528
532
|
end
|
529
533
|
|
530
534
|
it "does not mess with the stub's yielded values when also doubleed" do
|
531
535
|
@double.stub(:yield_back).and_yield(:stub_value)
|
532
536
|
@double.should_receive(:yield_back).and_yield(:double_value)
|
533
|
-
@double.yield_back{|v| v.
|
534
|
-
@double.yield_back{|v| v.
|
537
|
+
@double.yield_back{|v| expect(v).to eq :double_value }
|
538
|
+
@double.yield_back{|v| expect(v).to eq :stub_value }
|
535
539
|
@double.rspec_verify
|
536
540
|
end
|
537
541
|
|
@@ -540,14 +544,14 @@ module RSpec
|
|
540
544
|
File.should_receive(:open).and_yield(:first_call).and_yield(:second_call)
|
541
545
|
yielded_args = []
|
542
546
|
File.open {|v| yielded_args << v }
|
543
|
-
yielded_args.
|
544
|
-
File.open {|v| v.
|
547
|
+
expect(yielded_args).to eq [:first_call, :second_call]
|
548
|
+
File.open {|v| expect(v).to eq :stub_value }
|
545
549
|
File.rspec_verify
|
546
550
|
end
|
547
551
|
|
548
552
|
it "assigns stub return values" do
|
549
553
|
double = RSpec::Mocks::Mock.new('name', :message => :response)
|
550
|
-
double.message.
|
554
|
+
expect(double.message).to eq :response
|
551
555
|
end
|
552
556
|
|
553
557
|
end
|
@@ -567,7 +571,7 @@ module RSpec
|
|
567
571
|
|
568
572
|
@double.foo
|
569
573
|
|
570
|
-
@calls.
|
574
|
+
expect(@calls).to eq 1
|
571
575
|
end
|
572
576
|
|
573
577
|
it "calls the block after #should_receive after a similar stub" do
|
@@ -576,7 +580,7 @@ module RSpec
|
|
576
580
|
|
577
581
|
@double.foo
|
578
582
|
|
579
|
-
@calls.
|
583
|
+
expect(@calls).to eq 1
|
580
584
|
end
|
581
585
|
|
582
586
|
it "calls the block after #once" do
|
@@ -584,7 +588,7 @@ module RSpec
|
|
584
588
|
|
585
589
|
@double.foo
|
586
590
|
|
587
|
-
@calls.
|
591
|
+
expect(@calls).to eq 1
|
588
592
|
end
|
589
593
|
|
590
594
|
it "calls the block after #twice" do
|
@@ -593,7 +597,7 @@ module RSpec
|
|
593
597
|
@double.foo
|
594
598
|
@double.foo
|
595
599
|
|
596
|
-
@calls.
|
600
|
+
expect(@calls).to eq 2
|
597
601
|
end
|
598
602
|
|
599
603
|
it "calls the block after #times" do
|
@@ -601,7 +605,7 @@ module RSpec
|
|
601
605
|
|
602
606
|
(1..10).each { @double.foo }
|
603
607
|
|
604
|
-
@calls.
|
608
|
+
expect(@calls).to eq 10
|
605
609
|
end
|
606
610
|
|
607
611
|
it "calls the block after #any_number_of_times" do
|
@@ -609,7 +613,7 @@ module RSpec
|
|
609
613
|
|
610
614
|
(1..7).each { @double.foo }
|
611
615
|
|
612
|
-
@calls.
|
616
|
+
expect(@calls).to eq 7
|
613
617
|
end
|
614
618
|
|
615
619
|
it "calls the block after #ordered" do
|
@@ -619,7 +623,7 @@ module RSpec
|
|
619
623
|
@double.foo
|
620
624
|
@double.bar
|
621
625
|
|
622
|
-
@calls.
|
626
|
+
expect(@calls).to eq 2
|
623
627
|
end
|
624
628
|
end
|
625
629
|
|
@@ -627,14 +631,14 @@ module RSpec
|
|
627
631
|
it 'does not contain < because that might lead to invalid HTML in some situations' do
|
628
632
|
double = double("Dog")
|
629
633
|
valid_html_str = "#{double}"
|
630
|
-
valid_html_str.
|
634
|
+
expect(valid_html_str).not_to include('<')
|
631
635
|
end
|
632
636
|
end
|
633
637
|
|
634
638
|
describe "string representation generated by #to_str" do
|
635
639
|
it "looks the same as #to_s" do
|
636
640
|
double = double("Foo")
|
637
|
-
double.to_str.
|
641
|
+
expect(double.to_str).to eq double.to_s
|
638
642
|
end
|
639
643
|
end
|
640
644
|
|
@@ -646,8 +650,8 @@ module RSpec
|
|
646
650
|
|
647
651
|
it "does respond to initially stubbed methods" do
|
648
652
|
double = double(:foo => "woo", :bar => "car")
|
649
|
-
double.foo.
|
650
|
-
double.bar.
|
653
|
+
expect(double.foo).to eq "woo"
|
654
|
+
expect(double.bar).to eq "car"
|
651
655
|
end
|
652
656
|
end
|
653
657
|
|
@@ -710,7 +714,7 @@ module RSpec
|
|
710
714
|
context "with matching args" do
|
711
715
|
it "returns the result of the block" do
|
712
716
|
@double.should_receive(:foo).with('bar') { 'baz' }
|
713
|
-
@double.foo('bar').
|
717
|
+
expect(@double.foo('bar')).to eq('baz')
|
714
718
|
end
|
715
719
|
end
|
716
720
|
|
@@ -718,7 +722,7 @@ module RSpec
|
|
718
722
|
it "fails" do
|
719
723
|
@double.should_receive(:foo).with('bar') { 'baz' }
|
720
724
|
expect do
|
721
|
-
@double.foo('wrong').
|
725
|
+
expect(@double.foo('wrong')).to eq('baz')
|
722
726
|
end.to raise_error(/received :foo with unexpected arguments/)
|
723
727
|
@double.rspec_reset
|
724
728
|
end
|