rspec-mocks 2.6.0 → 2.7.0
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/README.md +0 -19
- data/features/Scope.md +17 -0
- data/features/argument_matchers/README.md +27 -0
- data/features/argument_matchers/explicit.feature +60 -0
- data/features/argument_matchers/general_matchers.feature +85 -0
- data/features/argument_matchers/type_matchers.feature +25 -0
- data/features/message_expectations/any_instance.feature +2 -0
- data/features/message_expectations/receive_counts.feature +209 -0
- data/features/method_stubs/README.md +6 -10
- data/features/method_stubs/any_instance.feature +111 -1
- data/features/method_stubs/simple_return_value.feature +34 -25
- data/features/method_stubs/stub_implementation.feature +1 -1
- data/features/method_stubs/to_ary.feature +12 -10
- data/features/support/env.rb +1 -1
- data/lib/rspec/mocks/any_instance/chain.rb +49 -0
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +33 -0
- data/lib/rspec/mocks/any_instance/message_chains.rb +48 -0
- data/lib/rspec/mocks/any_instance/recorder.rb +168 -0
- data/lib/rspec/mocks/any_instance/stub_chain.rb +35 -0
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +34 -0
- data/lib/rspec/mocks/any_instance.rb +8 -235
- data/lib/rspec/mocks/argument_expectation.rb +1 -1
- data/lib/rspec/mocks/argument_matchers.rb +19 -25
- data/lib/rspec/mocks/extensions/marshal.rb +1 -1
- data/lib/rspec/mocks/extensions/psych.rb +1 -1
- data/lib/rspec/mocks/message_expectation.rb +7 -4
- data/lib/rspec/mocks/methods.rb +6 -8
- data/lib/rspec/mocks/mock.rb +2 -2
- data/lib/rspec/mocks/proxy.rb +4 -4
- data/lib/rspec/mocks/version.rb +4 -4
- data/lib/rspec/mocks.rb +13 -14
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +40 -0
- data/spec/rspec/mocks/any_instance_spec.rb +219 -24
- data/spec/rspec/mocks/any_number_of_times_spec.rb +2 -2
- data/spec/rspec/mocks/argument_expectation_spec.rb +15 -3
- data/spec/rspec/mocks/at_least_spec.rb +1 -1
- data/spec/rspec/mocks/at_most_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_10263_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_7611_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_8165_spec.rb +2 -2
- data/spec/rspec/mocks/bug_report_957_spec.rb +2 -2
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +1 -1
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +11 -11
- data/spec/rspec/mocks/hash_not_including_matcher_spec.rb +6 -6
- data/spec/rspec/mocks/mock_spec.rb +49 -43
- data/spec/rspec/mocks/multiple_return_value_spec.rb +26 -26
- data/spec/rspec/mocks/partial_mock_spec.rb +3 -2
- data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +1 -0
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -3
- data/spec/rspec/mocks/precise_counts_spec.rb +1 -1
- data/spec/rspec/mocks/serialization_spec.rb +7 -2
- data/spec/rspec/mocks/stub_implementation_spec.rb +6 -6
- data/spec/rspec/mocks/stub_spec.rb +6 -6
- data/spec/rspec/mocks/to_ary_spec.rb +9 -0
- metadata +45 -42
- data/.autotest +0 -7
- data/.document +0 -5
- data/.gitignore +0 -10
- data/.travis.yml +0 -7
- data/Gemfile +0 -40
- data/Guardfile +0 -8
- data/License.txt +0 -22
- data/Rakefile +0 -75
- data/autotest/discover.rb +0 -1
- data/cucumber.yml +0 -2
- data/features/.nav +0 -17
- data/features/Changelog.md +0 -80
- data/rspec-mocks.gemspec +0 -25
- data/specs.watchr +0 -57
|
@@ -78,20 +78,20 @@ module RSpec
|
|
|
78
78
|
|
|
79
79
|
it "allows block to calculate return values" do
|
|
80
80
|
@mock.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
|
|
81
|
-
@mock.something("a","b","c").should
|
|
81
|
+
@mock.something("a","b","c").should eq "cba"
|
|
82
82
|
@mock.rspec_verify
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it "allows parameter as return value" do
|
|
86
86
|
@mock.should_receive(:something).with("a","b","c").and_return("booh")
|
|
87
|
-
@mock.something("a","b","c").should
|
|
87
|
+
@mock.something("a","b","c").should eq "booh"
|
|
88
88
|
@mock.rspec_verify
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it "returns the previously stubbed value if no return value is set" do
|
|
92
|
-
@mock.stub
|
|
92
|
+
@mock.stub(:something).with("a","b","c").and_return(:stubbed_value)
|
|
93
93
|
@mock.should_receive(:something).with("a","b","c")
|
|
94
|
-
@mock.something("a","b","c").should
|
|
94
|
+
@mock.something("a","b","c").should eq :stubbed_value
|
|
95
95
|
@mock.rspec_verify
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -137,7 +137,19 @@ module RSpec
|
|
|
137
137
|
@mock.rspec_verify
|
|
138
138
|
}.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
|
|
139
139
|
end
|
|
140
|
-
|
|
140
|
+
|
|
141
|
+
describe 'with a method that has a default argument' do
|
|
142
|
+
it "raises an exception if the arguments don't match when the method is called, correctly reporting the offending arguments" do
|
|
143
|
+
def @mock.method_with_default_argument(arg={}); end
|
|
144
|
+
@mock.should_receive(:method_with_default_argument).with({})
|
|
145
|
+
|
|
146
|
+
expect {
|
|
147
|
+
@mock.method_with_default_argument(nil)
|
|
148
|
+
@mock.rspec_verify
|
|
149
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :method_with_default_argument with unexpected arguments\n expected: ({})\n got: (nil)")
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
141
153
|
it "fails if unexpected method called" do
|
|
142
154
|
lambda {
|
|
143
155
|
@mock.something("a","b","c")
|
|
@@ -147,11 +159,11 @@ module RSpec
|
|
|
147
159
|
|
|
148
160
|
it "uses block for expectation if provided" do
|
|
149
161
|
@mock.should_receive(:something) do | a, b |
|
|
150
|
-
a.should
|
|
151
|
-
b.should
|
|
162
|
+
a.should eq "a"
|
|
163
|
+
b.should eq "b"
|
|
152
164
|
"booh"
|
|
153
165
|
end
|
|
154
|
-
@mock.something("a", "b").should
|
|
166
|
+
@mock.something("a", "b").should eq "booh"
|
|
155
167
|
@mock.rspec_verify
|
|
156
168
|
end
|
|
157
169
|
|
|
@@ -169,8 +181,8 @@ module RSpec
|
|
|
169
181
|
eval("@mock.should_receive(:something) { |&block| a = block }")
|
|
170
182
|
b = lambda { }
|
|
171
183
|
@mock.something(&b)
|
|
172
|
-
a.should
|
|
173
|
-
@
|
|
184
|
+
a.should eq b
|
|
185
|
+
@mock.rspec_verify
|
|
174
186
|
end
|
|
175
187
|
|
|
176
188
|
it "fails right away when method defined as never is received" do
|
|
@@ -258,7 +270,7 @@ module RSpec
|
|
|
258
270
|
|
|
259
271
|
it "returns value from block by default" do
|
|
260
272
|
@mock.stub(:method_that_yields).and_yield
|
|
261
|
-
@mock.method_that_yields { :returned_obj }.should
|
|
273
|
+
@mock.method_that_yields { :returned_obj }.should eq :returned_obj
|
|
262
274
|
@mock.rspec_verify
|
|
263
275
|
end
|
|
264
276
|
|
|
@@ -266,17 +278,16 @@ module RSpec
|
|
|
266
278
|
@mock.should_receive(:yield_back).with(no_args()).once.and_yield
|
|
267
279
|
a = nil
|
|
268
280
|
@mock.yield_back {|*x| a = x}
|
|
269
|
-
a.should
|
|
281
|
+
a.should eq []
|
|
270
282
|
@mock.rspec_verify
|
|
271
283
|
end
|
|
272
284
|
|
|
273
285
|
it "yields 0 args multiple times to blocks that take a variable number of arguments" do
|
|
274
286
|
@mock.should_receive(:yield_back).once.with(no_args()).once.and_yield.
|
|
275
287
|
and_yield
|
|
276
|
-
a = nil
|
|
277
288
|
b = []
|
|
278
289
|
@mock.yield_back {|*a| b << a}
|
|
279
|
-
b.should
|
|
290
|
+
b.should eq [ [], [] ]
|
|
280
291
|
@mock.rspec_verify
|
|
281
292
|
end
|
|
282
293
|
|
|
@@ -284,7 +295,7 @@ module RSpec
|
|
|
284
295
|
@mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
|
|
285
296
|
a = nil
|
|
286
297
|
@mock.yield_back {|*x| a = x}
|
|
287
|
-
a.should
|
|
298
|
+
a.should eq [99]
|
|
288
299
|
@mock.rspec_verify
|
|
289
300
|
end
|
|
290
301
|
|
|
@@ -292,10 +303,9 @@ module RSpec
|
|
|
292
303
|
@mock.should_receive(:yield_back).once.with(no_args()).once.and_yield(99).
|
|
293
304
|
and_yield(43).
|
|
294
305
|
and_yield("something fruity")
|
|
295
|
-
a = nil
|
|
296
306
|
b = []
|
|
297
307
|
@mock.yield_back {|*a| b << a}
|
|
298
|
-
b.should
|
|
308
|
+
b.should eq [[99], [43], ["something fruity"]]
|
|
299
309
|
@mock.rspec_verify
|
|
300
310
|
end
|
|
301
311
|
|
|
@@ -303,7 +313,7 @@ module RSpec
|
|
|
303
313
|
@mock.should_receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go")
|
|
304
314
|
a = nil
|
|
305
315
|
@mock.yield_back {|*x| a = x}
|
|
306
|
-
a.should
|
|
316
|
+
a.should eq [99, 27, "go"]
|
|
307
317
|
@mock.rspec_verify
|
|
308
318
|
end
|
|
309
319
|
|
|
@@ -311,10 +321,9 @@ module RSpec
|
|
|
311
321
|
@mock.should_receive(:yield_back).once.with(no_args()).once.and_yield(99, :green, "go").
|
|
312
322
|
and_yield("wait", :amber).
|
|
313
323
|
and_yield("stop", 12, :red)
|
|
314
|
-
a = nil
|
|
315
324
|
b = []
|
|
316
325
|
@mock.yield_back {|*a| b << a}
|
|
317
|
-
b.should
|
|
326
|
+
b.should eq [[99, :green, "go"], ["wait", :amber], ["stop", 12, :red]]
|
|
318
327
|
@mock.rspec_verify
|
|
319
328
|
end
|
|
320
329
|
|
|
@@ -322,7 +331,7 @@ module RSpec
|
|
|
322
331
|
@mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
|
|
323
332
|
a = nil
|
|
324
333
|
@mock.yield_back {|x| a = x}
|
|
325
|
-
a.should
|
|
334
|
+
a.should eq 99
|
|
326
335
|
@mock.rspec_verify
|
|
327
336
|
end
|
|
328
337
|
|
|
@@ -330,10 +339,9 @@ module RSpec
|
|
|
330
339
|
@mock.should_receive(:yield_back).once.with(no_args()).once.and_yield(99).
|
|
331
340
|
and_yield(43).
|
|
332
341
|
and_yield("something fruity")
|
|
333
|
-
a = nil
|
|
334
342
|
b = []
|
|
335
343
|
@mock.yield_back {|a| b << a}
|
|
336
|
-
b.should
|
|
344
|
+
b.should eq [99, 43, "something fruity"]
|
|
337
345
|
@mock.rspec_verify
|
|
338
346
|
end
|
|
339
347
|
|
|
@@ -341,8 +349,8 @@ module RSpec
|
|
|
341
349
|
@mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
|
|
342
350
|
a, b = nil
|
|
343
351
|
@mock.yield_back {|x,y| a=x; b=y}
|
|
344
|
-
a.should
|
|
345
|
-
b.should
|
|
352
|
+
a.should eq 'wha'
|
|
353
|
+
b.should eq 'zup'
|
|
346
354
|
@mock.rspec_verify
|
|
347
355
|
end
|
|
348
356
|
|
|
@@ -350,10 +358,9 @@ module RSpec
|
|
|
350
358
|
@mock.should_receive(:yield_back).once.with(no_args()).once.and_yield('wha', 'zup').
|
|
351
359
|
and_yield('not', 'down').
|
|
352
360
|
and_yield(14, 65)
|
|
353
|
-
a, b = nil
|
|
354
361
|
c = []
|
|
355
362
|
@mock.yield_back {|a,b| c << [a, b]}
|
|
356
|
-
c.should
|
|
363
|
+
c.should eq [['wha', 'zup'], ['not', 'down'], [14, 65]]
|
|
357
364
|
@mock.rspec_verify
|
|
358
365
|
end
|
|
359
366
|
|
|
@@ -369,7 +376,6 @@ module RSpec
|
|
|
369
376
|
and_yield('down').
|
|
370
377
|
and_yield(14, 65)
|
|
371
378
|
lambda {
|
|
372
|
-
a, b = nil
|
|
373
379
|
c = []
|
|
374
380
|
@mock.yield_back {|a,b| c << [a, b]}
|
|
375
381
|
}.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" yielded |\"down\"| to block with arity of 2")
|
|
@@ -496,8 +502,8 @@ module RSpec
|
|
|
496
502
|
it "does not mess with the stub's yielded values when also mocked" do
|
|
497
503
|
@mock.stub(:yield_back).and_yield(:stub_value)
|
|
498
504
|
@mock.should_receive(:yield_back).and_yield(:mock_value)
|
|
499
|
-
@mock.yield_back{|v| v.should
|
|
500
|
-
@mock.yield_back{|v| v.should
|
|
505
|
+
@mock.yield_back{|v| v.should eq :mock_value }
|
|
506
|
+
@mock.yield_back{|v| v.should eq :stub_value }
|
|
501
507
|
@mock.rspec_verify
|
|
502
508
|
end
|
|
503
509
|
|
|
@@ -506,14 +512,14 @@ module RSpec
|
|
|
506
512
|
File.should_receive(:open).and_yield(:first_call).and_yield(:second_call)
|
|
507
513
|
yielded_args = []
|
|
508
514
|
File.open {|v| yielded_args << v }
|
|
509
|
-
yielded_args.should
|
|
510
|
-
File.open {|v| v.should
|
|
515
|
+
yielded_args.should eq [:first_call, :second_call]
|
|
516
|
+
File.open {|v| v.should eq :stub_value }
|
|
511
517
|
File.rspec_verify
|
|
512
518
|
end
|
|
513
519
|
|
|
514
520
|
it "assigns stub return values" do
|
|
515
521
|
mock = RSpec::Mocks::Mock.new('name', :message => :response)
|
|
516
|
-
mock.message.should
|
|
522
|
+
mock.message.should eq :response
|
|
517
523
|
end
|
|
518
524
|
|
|
519
525
|
end
|
|
@@ -533,7 +539,7 @@ module RSpec
|
|
|
533
539
|
|
|
534
540
|
@mock.foo
|
|
535
541
|
|
|
536
|
-
@calls.should
|
|
542
|
+
@calls.should eq 1
|
|
537
543
|
end
|
|
538
544
|
|
|
539
545
|
it "calls the block after #should_receive after a similar stub" do
|
|
@@ -542,7 +548,7 @@ module RSpec
|
|
|
542
548
|
|
|
543
549
|
@mock.foo
|
|
544
550
|
|
|
545
|
-
@calls.should
|
|
551
|
+
@calls.should eq 1
|
|
546
552
|
end
|
|
547
553
|
|
|
548
554
|
it "calls the block after #once" do
|
|
@@ -550,7 +556,7 @@ module RSpec
|
|
|
550
556
|
|
|
551
557
|
@mock.foo
|
|
552
558
|
|
|
553
|
-
@calls.should
|
|
559
|
+
@calls.should eq 1
|
|
554
560
|
end
|
|
555
561
|
|
|
556
562
|
it "calls the block after #twice" do
|
|
@@ -559,7 +565,7 @@ module RSpec
|
|
|
559
565
|
@mock.foo
|
|
560
566
|
@mock.foo
|
|
561
567
|
|
|
562
|
-
@calls.should
|
|
568
|
+
@calls.should eq 2
|
|
563
569
|
end
|
|
564
570
|
|
|
565
571
|
it "calls the block after #times" do
|
|
@@ -567,7 +573,7 @@ module RSpec
|
|
|
567
573
|
|
|
568
574
|
(1..10).each { @mock.foo }
|
|
569
575
|
|
|
570
|
-
@calls.should
|
|
576
|
+
@calls.should eq 10
|
|
571
577
|
end
|
|
572
578
|
|
|
573
579
|
it "calls the block after #any_number_of_times" do
|
|
@@ -575,7 +581,7 @@ module RSpec
|
|
|
575
581
|
|
|
576
582
|
(1..7).each { @mock.foo }
|
|
577
583
|
|
|
578
|
-
@calls.should
|
|
584
|
+
@calls.should eq 7
|
|
579
585
|
end
|
|
580
586
|
|
|
581
587
|
it "calls the block after #ordered" do
|
|
@@ -585,7 +591,7 @@ module RSpec
|
|
|
585
591
|
@mock.foo
|
|
586
592
|
@mock.bar
|
|
587
593
|
|
|
588
|
-
@calls.should
|
|
594
|
+
@calls.should eq 2
|
|
589
595
|
end
|
|
590
596
|
end
|
|
591
597
|
|
|
@@ -600,7 +606,7 @@ module RSpec
|
|
|
600
606
|
describe "string representation generated by #to_str" do
|
|
601
607
|
it "looks the same as #to_s" do
|
|
602
608
|
double = double("Foo")
|
|
603
|
-
double.to_str.should
|
|
609
|
+
double.to_str.should eq double.to_s
|
|
604
610
|
end
|
|
605
611
|
end
|
|
606
612
|
|
|
@@ -612,8 +618,8 @@ module RSpec
|
|
|
612
618
|
|
|
613
619
|
it "does respond to initially stubbed methods" do
|
|
614
620
|
double = double(:foo => "woo", :bar => "car")
|
|
615
|
-
double.foo.should
|
|
616
|
-
double.bar.should
|
|
621
|
+
double.foo.should eq "woo"
|
|
622
|
+
double.bar.should eq "car"
|
|
617
623
|
end
|
|
618
624
|
end
|
|
619
625
|
|
|
@@ -10,15 +10,15 @@ module RSpec
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "returns values in order to consecutive calls" do
|
|
13
|
-
@mock.message.should
|
|
14
|
-
@mock.message.should
|
|
15
|
-
@mock.message.should
|
|
13
|
+
@mock.message.should eq @return_values[0]
|
|
14
|
+
@mock.message.should eq @return_values[1]
|
|
15
|
+
@mock.message.should eq @return_values[2]
|
|
16
16
|
@mock.rspec_verify
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "complains when there are too few calls" do
|
|
20
|
-
@mock.message.should
|
|
21
|
-
@mock.message.should
|
|
20
|
+
@mock.message.should eq @return_values[0]
|
|
21
|
+
@mock.message.should eq @return_values[1]
|
|
22
22
|
expect { @mock.rspec_verify }.to raise_error(
|
|
23
23
|
RSpec::Mocks::MockExpectationError,
|
|
24
24
|
%Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
|
|
@@ -26,10 +26,10 @@ module RSpec
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "complains when there are too many calls" do
|
|
29
|
-
@mock.message.should
|
|
30
|
-
@mock.message.should
|
|
31
|
-
@mock.message.should
|
|
32
|
-
@mock.message.should
|
|
29
|
+
@mock.message.should eq @return_values[0]
|
|
30
|
+
@mock.message.should eq @return_values[1]
|
|
31
|
+
@mock.message.should eq @return_values[2]
|
|
32
|
+
@mock.message.should eq @return_values[2]
|
|
33
33
|
expect { @mock.rspec_verify }.to raise_error(
|
|
34
34
|
RSpec::Mocks::MockExpectationError,
|
|
35
35
|
%Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
|
|
@@ -38,10 +38,10 @@ module RSpec
|
|
|
38
38
|
|
|
39
39
|
it "doesn't complain when there are too many calls but method is stubbed too" do
|
|
40
40
|
@mock.stub(:message).and_return :stub_result
|
|
41
|
-
@mock.message.should
|
|
42
|
-
@mock.message.should
|
|
43
|
-
@mock.message.should
|
|
44
|
-
@mock.message.should
|
|
41
|
+
@mock.message.should eq @return_values[0]
|
|
42
|
+
@mock.message.should eq @return_values[1]
|
|
43
|
+
@mock.message.should eq @return_values[2]
|
|
44
|
+
@mock.message.should eq :stub_result
|
|
45
45
|
expect { @mock.rspec_verify }.to_not raise_error(RSpec::Mocks::MockExpectationError)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -54,16 +54,16 @@ module RSpec
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it "returns values in order to consecutive calls" do
|
|
57
|
-
@mock.message.should
|
|
58
|
-
@mock.message.should
|
|
59
|
-
@mock.message.should
|
|
57
|
+
@mock.message.should eq @return_values[0]
|
|
58
|
+
@mock.message.should eq @return_values[1]
|
|
59
|
+
@mock.message.should eq @return_values[2]
|
|
60
60
|
@mock.rspec_verify
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "complains when there are too few calls" do
|
|
64
64
|
third = Object.new
|
|
65
|
-
@mock.message.should
|
|
66
|
-
@mock.message.should
|
|
65
|
+
@mock.message.should eq @return_values[0]
|
|
66
|
+
@mock.message.should eq @return_values[1]
|
|
67
67
|
expect { @mock.rspec_verify }.to raise_error(
|
|
68
68
|
RSpec::Mocks::MockExpectationError,
|
|
69
69
|
%Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
|
|
@@ -72,10 +72,10 @@ module RSpec
|
|
|
72
72
|
|
|
73
73
|
it "complains when there are too many calls" do
|
|
74
74
|
third = Object.new
|
|
75
|
-
@mock.message.should
|
|
76
|
-
@mock.message.should
|
|
77
|
-
@mock.message.should
|
|
78
|
-
@mock.message.should
|
|
75
|
+
@mock.message.should eq @return_values[0]
|
|
76
|
+
@mock.message.should eq @return_values[1]
|
|
77
|
+
@mock.message.should eq @return_values[2]
|
|
78
|
+
@mock.message.should eq @return_values[2]
|
|
79
79
|
expect { @mock.rspec_verify }.to raise_error(
|
|
80
80
|
RSpec::Mocks::MockExpectationError,
|
|
81
81
|
%Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
|
|
@@ -85,10 +85,10 @@ module RSpec
|
|
|
85
85
|
it "complains when there are too many calls and method is stubbed too" do
|
|
86
86
|
third = Object.new
|
|
87
87
|
@mock.stub(:message).and_return :stub_result
|
|
88
|
-
@mock.message.should
|
|
89
|
-
@mock.message.should
|
|
90
|
-
@mock.message.should
|
|
91
|
-
@mock.message.should
|
|
88
|
+
@mock.message.should eq @return_values[0]
|
|
89
|
+
@mock.message.should eq @return_values[1]
|
|
90
|
+
@mock.message.should eq @return_values[2]
|
|
91
|
+
@mock.message.should eq :stub_result
|
|
92
92
|
expect { @mock.rspec_verify }.to raise_error(
|
|
93
93
|
RSpec::Mocks::MockExpectationError,
|
|
94
94
|
%Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
|
|
@@ -84,9 +84,10 @@ module RSpec
|
|
|
84
84
|
it "uses reports nil in the error message" do
|
|
85
85
|
allow_message_expectations_on_nil
|
|
86
86
|
|
|
87
|
-
@
|
|
87
|
+
@nil = nil
|
|
88
|
+
@nil.should_receive(:foobar)
|
|
88
89
|
expect {
|
|
89
|
-
@
|
|
90
|
+
@nil.rspec_verify
|
|
90
91
|
}.to raise_error(
|
|
91
92
|
RSpec::Mocks::MockExpectationError,
|
|
92
93
|
%Q|(nil).foobar(any args)\n expected: 1 time\n received: 0 times|
|
|
@@ -87,11 +87,11 @@ module RSpec
|
|
|
87
87
|
context "handling block matchers" do
|
|
88
88
|
it "matches arguments against RSpec expectations" do
|
|
89
89
|
@double.should_receive(:random_call).with {|arg1, arg2, arr, *rest|
|
|
90
|
-
arg1.should
|
|
90
|
+
arg1.should eq 5
|
|
91
91
|
arg2.should have_at_least(3).characters
|
|
92
92
|
arg2.should have_at_most(10).characters
|
|
93
|
-
arr.map {|i| i * 2}.should
|
|
94
|
-
rest.should
|
|
93
|
+
arr.map {|i| i * 2}.should eq [2,4,6]
|
|
94
|
+
rest.should eq [:fee, "fi", 4]
|
|
95
95
|
}
|
|
96
96
|
@double.random_call 5, "hello", [1,2,3], :fee, "fi", 4
|
|
97
97
|
end
|
|
@@ -33,7 +33,7 @@ module RSpec
|
|
|
33
33
|
|
|
34
34
|
it "returns the value given by a block when the exactly once method is called" do
|
|
35
35
|
@mock.should_receive(:to_s).exactly(:once) { "testing" }
|
|
36
|
-
@mock.to_s.should
|
|
36
|
+
@mock.to_s.should eq "testing"
|
|
37
37
|
@mock.rspec_verify
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -64,7 +64,12 @@ module RSpec
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
with_yaml_loaded do
|
|
67
|
-
compiled_with_psych =
|
|
67
|
+
compiled_with_psych = begin
|
|
68
|
+
require 'psych'
|
|
69
|
+
true
|
|
70
|
+
rescue LoadError => e
|
|
71
|
+
false
|
|
72
|
+
end
|
|
68
73
|
|
|
69
74
|
if compiled_with_psych
|
|
70
75
|
context 'using Syck as the YAML engine' do
|
|
@@ -98,7 +103,7 @@ module RSpec
|
|
|
98
103
|
|
|
99
104
|
it 'does not interfere with its marshalling' do
|
|
100
105
|
marshalled_copy = Marshal.load(Marshal.dump(subject))
|
|
101
|
-
marshalled_copy.should
|
|
106
|
+
marshalled_copy.should eq subject
|
|
102
107
|
end
|
|
103
108
|
end
|
|
104
109
|
end
|
|
@@ -7,7 +7,7 @@ module RSpec
|
|
|
7
7
|
it "execs the block when called" do
|
|
8
8
|
obj = stub()
|
|
9
9
|
obj.stub(:foo) { :bar }
|
|
10
|
-
obj.foo.should
|
|
10
|
+
obj.foo.should eq :bar
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ module RSpec
|
|
|
15
15
|
it "execs the block with that arg when called" do
|
|
16
16
|
obj = stub()
|
|
17
17
|
obj.stub(:foo) {|given| given}
|
|
18
|
-
obj.foo(:bar).should
|
|
18
|
+
obj.foo(:bar).should eq :bar
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -23,7 +23,7 @@ module RSpec
|
|
|
23
23
|
it "execs the block when called" do
|
|
24
24
|
obj = stub()
|
|
25
25
|
obj.stub(:foo) {|*given| given.first}
|
|
26
|
-
obj.foo(:bar).should
|
|
26
|
+
obj.foo(:bar).should eq :bar
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -35,7 +35,7 @@ module RSpec
|
|
|
35
35
|
def obj.foo; :original; end
|
|
36
36
|
obj.stub(:foo)
|
|
37
37
|
obj.unstub(:foo)
|
|
38
|
-
obj.foo.should
|
|
38
|
+
obj.foo.should eq :original
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "removes all stubs with the supplied method name" do
|
|
@@ -44,7 +44,7 @@ module RSpec
|
|
|
44
44
|
obj.stub(:foo).with(1)
|
|
45
45
|
obj.stub(:foo).with(2)
|
|
46
46
|
obj.unstub(:foo)
|
|
47
|
-
obj.foo.should
|
|
47
|
+
obj.foo.should eq :original
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "does not remove any expectations with the same method name" do
|
|
@@ -54,7 +54,7 @@ module RSpec
|
|
|
54
54
|
obj.stub(:foo).with(1)
|
|
55
55
|
obj.stub(:foo).with(2)
|
|
56
56
|
obj.unstub(:foo)
|
|
57
|
-
obj.foo(3).should
|
|
57
|
+
obj.foo(3).should eq :three
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it "raises a MockExpectationError if the method has not been stubbed" do
|
|
@@ -134,7 +134,7 @@ module RSpec
|
|
|
134
134
|
@instance.stub(:method_that_yields).and_yield(:yielded_obj)
|
|
135
135
|
current_value = :value_before
|
|
136
136
|
@instance.method_that_yields {|val| current_value = val}
|
|
137
|
-
current_value.should
|
|
137
|
+
current_value.should eq :yielded_obj
|
|
138
138
|
@instance.rspec_verify
|
|
139
139
|
end
|
|
140
140
|
|
|
@@ -143,7 +143,7 @@ module RSpec
|
|
|
143
143
|
and_yield(:another_value)
|
|
144
144
|
current_value = []
|
|
145
145
|
@instance.method_that_yields_multiple_times {|val| current_value << val}
|
|
146
|
-
current_value.should
|
|
146
|
+
current_value.should eq [:yielded_value, :another_value]
|
|
147
147
|
@instance.rspec_verify
|
|
148
148
|
end
|
|
149
149
|
|
|
@@ -151,7 +151,7 @@ module RSpec
|
|
|
151
151
|
yielded_obj = double("my mock")
|
|
152
152
|
yielded_obj.should_receive(:foo).with(:bar)
|
|
153
153
|
@instance.stub(:method_that_yields_and_returns).and_yield(yielded_obj).and_return(:baz)
|
|
154
|
-
@instance.method_that_yields_and_returns { |o| o.foo :bar }.should
|
|
154
|
+
@instance.method_that_yields_and_returns { |o| o.foo :bar }.should eq :baz
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
it "throws when told to" do
|
|
@@ -163,13 +163,13 @@ module RSpec
|
|
|
163
163
|
|
|
164
164
|
it "overrides a pre-existing method" do
|
|
165
165
|
@stub.stub(:existing_instance_method).and_return(:updated_stub_value)
|
|
166
|
-
@stub.existing_instance_method.should
|
|
166
|
+
@stub.existing_instance_method.should eq :updated_stub_value
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
it "overrides a pre-existing stub" do
|
|
170
170
|
@stub.stub(:foo) { 'bar' }
|
|
171
171
|
@stub.stub(:foo) { 'baz' }
|
|
172
|
-
@stub.foo.should
|
|
172
|
+
@stub.foo.should eq 'baz'
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
it "allows a stub and an expectation" do
|
|
@@ -181,7 +181,7 @@ module RSpec
|
|
|
181
181
|
|
|
182
182
|
it "calculates return value by executing block passed to #and_return" do
|
|
183
183
|
@stub.stub(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
|
|
184
|
-
@stub.something("a","b","c").should
|
|
184
|
+
@stub.something("a","b","c").should eq "cba"
|
|
185
185
|
@stub.rspec_verify
|
|
186
186
|
end
|
|
187
187
|
end
|
|
@@ -7,11 +7,20 @@ describe "a double receiving to_ary" do
|
|
|
7
7
|
obj.to_ary.should be_nil
|
|
8
8
|
end.to raise_error(NoMethodError)
|
|
9
9
|
end
|
|
10
|
+
|
|
11
|
+
it "doesn't respond" do
|
|
12
|
+
obj.should_not respond_to(:to_ary)
|
|
13
|
+
end
|
|
10
14
|
|
|
11
15
|
it "can be overridden with a stub" do
|
|
12
16
|
obj.stub(:to_ary) { :non_nil_value }
|
|
13
17
|
obj.to_ary.should be(:non_nil_value)
|
|
14
18
|
end
|
|
19
|
+
|
|
20
|
+
it "responds when overriden" do
|
|
21
|
+
obj.stub(:to_ary) { :non_nil_value }
|
|
22
|
+
obj.should respond_to(:to_ary)
|
|
23
|
+
end
|
|
15
24
|
|
|
16
25
|
it "supports Array#flatten" do
|
|
17
26
|
obj = double('foo')
|