rspec-mocks 2.13.1 → 2.14.0.rc1
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/Changelog.md +45 -4
- data/README.md +1 -1
- data/features/argument_matchers/README.md +2 -2
- data/features/argument_matchers/explicit.feature +2 -3
- data/features/argument_matchers/general_matchers.feature +2 -2
- data/features/argument_matchers/type_matchers.feature +3 -4
- data/features/message_expectations/README.md +2 -2
- data/features/message_expectations/any_instance.feature +2 -2
- data/features/message_expectations/block_local_expectations.feature.pending +3 -3
- data/features/message_expectations/expect_message_using_expect.feature +103 -0
- data/features/message_expectations/expect_message_using_should_receive.feature +118 -0
- data/features/message_expectations/receive_counts.feature +1 -1
- data/features/method_stubs/README.md +1 -1
- data/features/method_stubs/any_instance.feature +11 -11
- data/features/method_stubs/as_null_object.feature +1 -1
- data/features/method_stubs/stub_implementation.feature +2 -2
- data/features/outside_rspec/configuration.feature +0 -20
- data/features/spies/spy_partial_mock_method.feature +34 -0
- data/features/spies/spy_pure_mock_method.feature +76 -0
- data/features/spies/spy_unstubbed_method.feature +18 -0
- data/features/step_definitions/additional_cli_steps.rb +7 -0
- data/features/test_frameworks/test_unit.feature +43 -0
- data/lib/rspec/mocks.rb +9 -34
- data/lib/rspec/mocks/any_instance/chain.rb +8 -2
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +19 -16
- data/lib/rspec/mocks/any_instance/recorder.rb +6 -3
- data/lib/rspec/mocks/any_instance/stub_chain.rb +11 -11
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +8 -10
- data/lib/rspec/mocks/argument_list_matcher.rb +7 -3
- data/lib/rspec/mocks/configuration.rb +28 -1
- data/lib/rspec/mocks/deprecation.rb +18 -0
- data/lib/rspec/mocks/error_generator.rb +60 -8
- data/lib/rspec/mocks/errors.rb +1 -1
- data/lib/rspec/mocks/example_methods.rb +39 -3
- data/lib/rspec/mocks/extensions/marshal.rb +4 -10
- data/lib/rspec/mocks/framework.rb +16 -4
- data/lib/rspec/mocks/instance_method_stasher.rb +3 -0
- data/lib/rspec/mocks/matchers/have_received.rb +93 -0
- data/lib/rspec/mocks/matchers/receive.rb +92 -0
- data/lib/rspec/mocks/message_expectation.rb +66 -129
- data/lib/rspec/mocks/method_double.rb +50 -43
- data/lib/rspec/mocks/mutate_const.rb +8 -20
- data/lib/rspec/mocks/proxy.rb +41 -25
- data/lib/rspec/mocks/proxy_for_nil.rb +36 -0
- data/lib/rspec/mocks/space.rb +64 -11
- data/lib/rspec/mocks/stub_chain.rb +51 -0
- data/lib/rspec/mocks/syntax.rb +329 -0
- data/lib/rspec/mocks/targets.rb +69 -0
- data/lib/rspec/mocks/test_double.rb +25 -4
- data/lib/rspec/mocks/version.rb +1 -1
- data/lib/spec/mocks.rb +1 -3
- data/spec/rspec/mocks/and_call_original_spec.rb +8 -0
- data/spec/rspec/mocks/and_yield_spec.rb +6 -6
- data/spec/rspec/mocks/any_instance_spec.rb +43 -31
- data/spec/rspec/mocks/any_number_of_times_spec.rb +6 -0
- data/spec/rspec/mocks/argument_expectation_spec.rb +12 -14
- data/spec/rspec/mocks/at_least_spec.rb +46 -37
- data/spec/rspec/mocks/at_most_spec.rb +12 -12
- data/spec/rspec/mocks/block_return_value_spec.rb +18 -1
- data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_10263_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_11545_spec.rb +4 -4
- 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/configuration_spec.rb +124 -0
- data/spec/rspec/mocks/double_spec.rb +13 -1
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +17 -1
- data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +13 -13
- data/spec/rspec/mocks/matchers/have_received_spec.rb +266 -0
- data/spec/rspec/mocks/matchers/receive_spec.rb +318 -0
- data/spec/rspec/mocks/methods_spec.rb +27 -0
- data/spec/rspec/mocks/mock_ordering_spec.rb +4 -4
- data/spec/rspec/mocks/mock_space_spec.rb +94 -39
- data/spec/rspec/mocks/mock_spec.rb +65 -50
- data/spec/rspec/mocks/multiple_return_value_spec.rb +10 -10
- data/spec/rspec/mocks/mutate_const_spec.rb +21 -1
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +10 -4
- data/spec/rspec/mocks/null_object_mock_spec.rb +11 -2
- data/spec/rspec/mocks/once_counts_spec.rb +5 -5
- data/spec/rspec/mocks/options_hash_spec.rb +4 -4
- data/spec/rspec/mocks/partial_mock_spec.rb +20 -11
- data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +7 -7
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +2 -2
- data/spec/rspec/mocks/precise_counts_spec.rb +6 -6
- data/spec/rspec/mocks/serialization_spec.rb +1 -22
- data/spec/rspec/mocks/stash_spec.rb +4 -12
- data/spec/rspec/mocks/stub_implementation_spec.rb +3 -3
- data/spec/rspec/mocks/stub_spec.rb +44 -20
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +6 -6
- data/spec/rspec/mocks/twice_counts_spec.rb +6 -6
- data/spec/rspec/mocks_spec.rb +1 -3
- data/spec/spec_helper.rb +25 -1
- metadata +86 -81
- data/features/message_expectations/expect_message.feature +0 -94
- data/lib/rspec/mocks/any_instance.rb +0 -81
- data/lib/rspec/mocks/extensions/psych.rb +0 -23
- data/lib/rspec/mocks/methods.rb +0 -155
- data/lib/rspec/mocks/serialization.rb +0 -34
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +0 -197
@@ -4,8 +4,6 @@ module RSpec
|
|
4
4
|
# includes this module, and it is provided for cases where you want a
|
5
5
|
# pure test double without subclassing RSpec::Mocks::Mock.
|
6
6
|
module TestDouble
|
7
|
-
include Methods
|
8
|
-
|
9
7
|
# Extends the TestDouble module onto the given object and
|
10
8
|
# initializes it as a test double.
|
11
9
|
#
|
@@ -25,6 +23,18 @@ module RSpec
|
|
25
23
|
__initialize_as_test_double(name, stubs_and_options)
|
26
24
|
end
|
27
25
|
|
26
|
+
# Tells the object to respond to all messages. If specific stub values
|
27
|
+
# are declared, they'll work as expected. If not, the receiver is
|
28
|
+
# returned.
|
29
|
+
def as_null_object
|
30
|
+
__mock_proxy.as_null_object
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns true if this object has received `as_null_object`
|
34
|
+
def null_object?
|
35
|
+
__mock_proxy.null_object?
|
36
|
+
end
|
37
|
+
|
28
38
|
# This allows for comparing the mock to other objects that proxy such as
|
29
39
|
# ActiveRecords belongs_to proxy objects. By making the other object run
|
30
40
|
# the comparison, we're sure the call gets delegated to the proxy
|
@@ -50,6 +60,11 @@ module RSpec
|
|
50
60
|
__mock_proxy.null_object? && message != :to_ary ? true : super
|
51
61
|
end
|
52
62
|
|
63
|
+
# @private
|
64
|
+
def __build_mock_proxy
|
65
|
+
Proxy.new(self, @name, @options)
|
66
|
+
end
|
67
|
+
|
53
68
|
private
|
54
69
|
|
55
70
|
def __initialize_as_test_double(name=nil, stubs_and_options={})
|
@@ -64,7 +79,7 @@ module RSpec
|
|
64
79
|
end
|
65
80
|
|
66
81
|
def method_missing(message, *args, &block)
|
67
|
-
raise NoMethodError if message == :to_ary
|
82
|
+
raise NoMethodError if message == :to_ary || message == :to_a
|
68
83
|
return 0 if message == :to_int && __mock_proxy.null_object?
|
69
84
|
__mock_proxy.record_message_received(message, *args, &block)
|
70
85
|
|
@@ -78,7 +93,7 @@ module RSpec
|
|
78
93
|
def extract_options(stubs_and_options)
|
79
94
|
if stubs_and_options[:null_object]
|
80
95
|
@null_object = stubs_and_options.delete(:null_object)
|
81
|
-
RSpec.deprecate(
|
96
|
+
RSpec.deprecate("double('name', :null_object => true)", :replacement => "double('name').as_null_object")
|
82
97
|
end
|
83
98
|
options = {}
|
84
99
|
extract_option(stubs_and_options, options, :__declared_as, 'Mock')
|
@@ -98,6 +113,12 @@ module RSpec
|
|
98
113
|
stub(message).and_return(response)
|
99
114
|
end
|
100
115
|
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def __mock_proxy
|
120
|
+
::RSpec::Mocks.proxy_for(self)
|
121
|
+
end
|
101
122
|
end
|
102
123
|
end
|
103
124
|
end
|
data/lib/rspec/mocks/version.rb
CHANGED
data/lib/spec/mocks.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# For backward compatibility with rspec-1
|
2
2
|
require 'rspec/mocks'
|
3
3
|
|
4
|
-
RSpec
|
5
|
-
" is deprecated. Please require 'rspec/mocks' instead."
|
6
|
-
|
4
|
+
RSpec.deprecate "require 'spec/mocks'", :replacement => "require 'rspec/mocks'"
|
@@ -32,6 +32,14 @@ describe "and_call_original" do
|
|
32
32
|
expect(value).to eq([:submitted_arg, :additional_yielded_arg])
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'errors when you pass through the wrong number of args' do
|
36
|
+
instance.stub(:meth_1).and_call_original
|
37
|
+
instance.stub(:meth_2).and_call_original
|
38
|
+
expect { instance.meth_1 :a }.to raise_error ArgumentError
|
39
|
+
expect { instance.meth_2 {} }.to raise_error ArgumentError
|
40
|
+
expect { instance.meth_2(:a, :b) {} }.to raise_error ArgumentError
|
41
|
+
end
|
42
|
+
|
35
43
|
context "for singleton methods" do
|
36
44
|
it 'works' do
|
37
45
|
def instance.foo; :bar; end
|
@@ -62,7 +62,7 @@ describe RSpec::Mocks::Mock do
|
|
62
62
|
foo
|
63
63
|
end
|
64
64
|
|
65
|
-
configured_eval_context
|
65
|
+
verify configured_eval_context
|
66
66
|
end
|
67
67
|
|
68
68
|
it "fails when expectations set on the eval context are not met" do
|
@@ -76,7 +76,7 @@ describe RSpec::Mocks::Mock do
|
|
76
76
|
# foo is not called here
|
77
77
|
end
|
78
78
|
|
79
|
-
expect { configured_eval_context
|
79
|
+
expect { verify configured_eval_context }.to raise_error(RSpec::Mocks::MockExpectationError)
|
80
80
|
end
|
81
81
|
|
82
82
|
end
|
@@ -97,8 +97,8 @@ describe RSpec::Mocks::Mock do
|
|
97
97
|
foo
|
98
98
|
end
|
99
99
|
|
100
|
-
configured_eval_context
|
101
|
-
yielded_arg
|
100
|
+
verify configured_eval_context
|
101
|
+
verify yielded_arg
|
102
102
|
end
|
103
103
|
|
104
104
|
it "fails when expectations set on the eval context and yielded arguments are not met" do
|
@@ -115,8 +115,8 @@ describe RSpec::Mocks::Mock do
|
|
115
115
|
# foo is not called here
|
116
116
|
end
|
117
117
|
|
118
|
-
expect { configured_eval_context
|
119
|
-
expect { yielded_arg
|
118
|
+
expect { verify configured_eval_context }.to raise_error(RSpec::Mocks::MockExpectationError)
|
119
|
+
expect { verify yielded_arg }.to raise_error(RSpec::Mocks::MockExpectationError)
|
120
120
|
end
|
121
121
|
|
122
122
|
end
|
@@ -108,6 +108,13 @@ module RSpec
|
|
108
108
|
klass.any_instance.stub(:foo).and_return(result = Object.new)
|
109
109
|
expect(instance.foo).to eq(result)
|
110
110
|
end
|
111
|
+
|
112
|
+
it 'handles freeze and duplication correctly' do
|
113
|
+
String.any_instance.stub(:any_method)
|
114
|
+
|
115
|
+
foo = 'foo'.freeze
|
116
|
+
expect(foo.dup.concat 'bar').to eq 'foobar'
|
117
|
+
end
|
111
118
|
end
|
112
119
|
|
113
120
|
context "with argument matching" do
|
@@ -317,7 +324,7 @@ module RSpec
|
|
317
324
|
klass.any_instance.should_receive(:foo)
|
318
325
|
klass.any_instance.should_not_receive(:bar)
|
319
326
|
klass.new.foo
|
320
|
-
|
327
|
+
RSpec::Mocks.space.verify_all
|
321
328
|
end
|
322
329
|
end
|
323
330
|
end
|
@@ -336,14 +343,14 @@ module RSpec
|
|
336
343
|
expect do
|
337
344
|
klass.any_instance.should_receive(:foo)
|
338
345
|
klass.new
|
339
|
-
|
346
|
+
RSpec::Mocks.space.verify_all
|
340
347
|
end.to raise_error(RSpec::Mocks::MockExpectationError, foo_expectation_error_message)
|
341
348
|
end
|
342
349
|
|
343
350
|
it "fails if no instance is created" do
|
344
351
|
expect do
|
345
352
|
klass.any_instance.should_receive(:foo).and_return(1)
|
346
|
-
|
353
|
+
RSpec::Mocks.space.verify_all
|
347
354
|
end.to raise_error(RSpec::Mocks::MockExpectationError, foo_expectation_error_message)
|
348
355
|
end
|
349
356
|
|
@@ -351,7 +358,7 @@ module RSpec
|
|
351
358
|
expect do
|
352
359
|
klass.any_instance.should_receive(:foo)
|
353
360
|
klass.any_instance.should_receive(:bar)
|
354
|
-
|
361
|
+
RSpec::Mocks.space.verify_all
|
355
362
|
end.to raise_error(RSpec::Mocks::MockExpectationError, 'Exactly one instance should have received the following message(s) but didn\'t: bar, foo')
|
356
363
|
end
|
357
364
|
|
@@ -389,7 +396,7 @@ module RSpec
|
|
389
396
|
klass.any_instance.should_receive(:foo)
|
390
397
|
klass.should_receive(:woot)
|
391
398
|
klass.new.foo
|
392
|
-
|
399
|
+
RSpec::Mocks.space.verify_all
|
393
400
|
end.to(raise_error(RSpec::Mocks::MockExpectationError) do |error|
|
394
401
|
expect(error.message).not_to eq(existing_method_expectation_error_message)
|
395
402
|
end)
|
@@ -415,14 +422,14 @@ module RSpec
|
|
415
422
|
expect do
|
416
423
|
klass.any_instance.should_receive(:existing_method)
|
417
424
|
klass.new
|
418
|
-
|
425
|
+
RSpec::Mocks.space.verify_all
|
419
426
|
end.to raise_error(RSpec::Mocks::MockExpectationError, existing_method_expectation_error_message)
|
420
427
|
end
|
421
428
|
|
422
429
|
it "fails if no instance is created" do
|
423
430
|
expect do
|
424
431
|
klass.any_instance.should_receive(:existing_method)
|
425
|
-
|
432
|
+
RSpec::Mocks.space.verify_all
|
426
433
|
end.to raise_error(RSpec::Mocks::MockExpectationError, existing_method_expectation_error_message)
|
427
434
|
end
|
428
435
|
|
@@ -430,7 +437,7 @@ module RSpec
|
|
430
437
|
expect do
|
431
438
|
klass.any_instance.should_receive(:existing_method)
|
432
439
|
klass.any_instance.should_receive(:another_existing_method)
|
433
|
-
|
440
|
+
RSpec::Mocks.space.verify_all
|
434
441
|
end.to raise_error(RSpec::Mocks::MockExpectationError, 'Exactly one instance should have received the following message(s) but didn\'t: another_existing_method, existing_method')
|
435
442
|
end
|
436
443
|
|
@@ -493,7 +500,7 @@ module RSpec
|
|
493
500
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
494
501
|
|
495
502
|
# ignore the fact that should_receive expectations were not met
|
496
|
-
instances.each { |instance| instance
|
503
|
+
instances.each { |instance| reset instance }
|
497
504
|
end
|
498
505
|
|
499
506
|
it "is not affected by the invocation of existing methods on other instances" do
|
@@ -510,7 +517,7 @@ module RSpec
|
|
510
517
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
511
518
|
|
512
519
|
# ignore the fact that should_receive expectations were not met
|
513
|
-
instance
|
520
|
+
reset instance
|
514
521
|
end
|
515
522
|
end
|
516
523
|
|
@@ -524,7 +531,7 @@ module RSpec
|
|
524
531
|
it "fails when no instances are declared" do
|
525
532
|
expect do
|
526
533
|
klass.any_instance.should_receive(:foo).once
|
527
|
-
|
534
|
+
RSpec::Mocks.space.verify_all
|
528
535
|
end.to raise_error(RSpec::Mocks::MockExpectationError, foo_expectation_error_message)
|
529
536
|
end
|
530
537
|
|
@@ -532,7 +539,7 @@ module RSpec
|
|
532
539
|
expect do
|
533
540
|
klass.any_instance.should_receive(:foo).once
|
534
541
|
klass.new
|
535
|
-
|
542
|
+
RSpec::Mocks.space.verify_all
|
536
543
|
end.to raise_error(RSpec::Mocks::MockExpectationError, foo_expectation_error_message)
|
537
544
|
end
|
538
545
|
|
@@ -541,7 +548,7 @@ module RSpec
|
|
541
548
|
klass.any_instance.should_receive(:foo).once
|
542
549
|
instance = klass.new
|
543
550
|
2.times { instance.foo }
|
544
|
-
instance
|
551
|
+
verify instance
|
545
552
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
546
553
|
end
|
547
554
|
end
|
@@ -558,7 +565,7 @@ module RSpec
|
|
558
565
|
klass.any_instance.should_receive(:foo).twice
|
559
566
|
instance = klass.new
|
560
567
|
3.times { instance.foo }
|
561
|
-
instance
|
568
|
+
verify instance
|
562
569
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
563
570
|
end
|
564
571
|
end
|
@@ -575,7 +582,7 @@ module RSpec
|
|
575
582
|
klass.any_instance.should_receive(:foo).exactly(3).times
|
576
583
|
instance = klass.new
|
577
584
|
2.times { instance.foo }
|
578
|
-
instance
|
585
|
+
verify instance
|
579
586
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
580
587
|
end
|
581
588
|
|
@@ -584,7 +591,7 @@ module RSpec
|
|
584
591
|
klass.any_instance.should_receive(:foo).exactly(3).times
|
585
592
|
instance = klass.new
|
586
593
|
4.times { instance.foo }
|
587
|
-
instance
|
594
|
+
verify instance
|
588
595
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
589
596
|
end
|
590
597
|
end
|
@@ -601,7 +608,7 @@ module RSpec
|
|
601
608
|
klass.any_instance.should_receive(:foo).at_least(3).times
|
602
609
|
instance = klass.new
|
603
610
|
2.times { instance.foo }
|
604
|
-
instance
|
611
|
+
verify instance
|
605
612
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
606
613
|
end
|
607
614
|
|
@@ -630,7 +637,7 @@ module RSpec
|
|
630
637
|
klass.any_instance.should_receive(:foo).at_most(3).times
|
631
638
|
instance = klass.new
|
632
639
|
4.times { instance.foo }
|
633
|
-
instance
|
640
|
+
verify instance
|
634
641
|
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
635
642
|
end
|
636
643
|
end
|
@@ -638,7 +645,7 @@ module RSpec
|
|
638
645
|
context "the 'never' constraint" do
|
639
646
|
it "passes for 0 invocations" do
|
640
647
|
klass.any_instance.should_receive(:foo).never
|
641
|
-
|
648
|
+
RSpec::Mocks.space.verify_all
|
642
649
|
end
|
643
650
|
|
644
651
|
it "fails on the first invocation" do
|
@@ -659,7 +666,7 @@ module RSpec
|
|
659
666
|
expect do
|
660
667
|
klass.any_instance.should_receive(:foo).never
|
661
668
|
klass.any_instance.should_receive(:existing_method).and_return(5)
|
662
|
-
|
669
|
+
RSpec::Mocks.space.verify_all
|
663
670
|
end.to raise_error(RSpec::Mocks::MockExpectationError, existing_method_expectation_error_message)
|
664
671
|
end
|
665
672
|
end
|
@@ -668,14 +675,16 @@ module RSpec
|
|
668
675
|
context "the 'any_number_of_times' constraint" do
|
669
676
|
it "passes for 0 invocations" do
|
670
677
|
klass.any_instance.should_receive(:foo).any_number_of_times
|
671
|
-
klass.new
|
678
|
+
verify klass.new
|
672
679
|
end
|
673
680
|
|
674
681
|
it "passes for a non-zero number of invocations" do
|
682
|
+
allow(RSpec).to receive(:deprecate).with("any_number_of_times", :replacement => "stub")
|
683
|
+
|
675
684
|
klass.any_instance.should_receive(:foo).any_number_of_times
|
676
685
|
instance = klass.new
|
677
686
|
instance.foo
|
678
|
-
instance
|
687
|
+
verify instance
|
679
688
|
end
|
680
689
|
|
681
690
|
it "does not interfere with other expectations" do
|
@@ -695,7 +704,7 @@ module RSpec
|
|
695
704
|
expect do
|
696
705
|
klass.any_instance.should_receive(:foo).any_number_of_times
|
697
706
|
klass.any_instance.should_receive(:existing_method).and_return(5)
|
698
|
-
|
707
|
+
RSpec::Mocks.space.verify_all
|
699
708
|
end.to raise_error(RSpec::Mocks::MockExpectationError, existing_method_expectation_error_message)
|
700
709
|
end
|
701
710
|
end
|
@@ -704,11 +713,11 @@ module RSpec
|
|
704
713
|
end
|
705
714
|
|
706
715
|
context "when resetting post-verification" do
|
707
|
-
let(:space) { RSpec::Mocks
|
716
|
+
let(:space) { RSpec::Mocks.space }
|
708
717
|
|
709
718
|
context "existing method" do
|
710
719
|
before(:each) do
|
711
|
-
|
720
|
+
klass.any_instance # to force it to be tracked
|
712
721
|
end
|
713
722
|
|
714
723
|
context "with stubbing" do
|
@@ -829,31 +838,34 @@ module RSpec
|
|
829
838
|
klass.any_instance.stub(:existing_method).and_return(false)
|
830
839
|
klass.any_instance.stub(:existing_method).and_return(true)
|
831
840
|
|
832
|
-
|
841
|
+
RSpec::Mocks.space.verify_all
|
833
842
|
expect(klass.new).to respond_to(:existing_method)
|
834
843
|
expect(klass.new.existing_method).to eq(existing_method_return_value)
|
835
844
|
end
|
836
845
|
end
|
837
846
|
|
838
847
|
it "adds an class to the current space when #any_instance is invoked" do
|
839
|
-
|
840
|
-
|
848
|
+
expect {
|
849
|
+
klass.any_instance
|
850
|
+
}.to change { space.any_instance_recorders.size }.by(1)
|
841
851
|
end
|
842
852
|
|
843
853
|
it "adds an instance to the current space when stubbed method is invoked" do
|
844
854
|
klass.any_instance.stub(:foo)
|
845
855
|
instance = klass.new
|
846
856
|
instance.foo
|
847
|
-
expect(RSpec::Mocks
|
857
|
+
expect(RSpec::Mocks.space.proxies.keys).to include(instance.object_id)
|
848
858
|
end
|
849
859
|
end
|
850
860
|
|
851
861
|
context 'when used in conjunction with a `dup`' do
|
852
862
|
it "doesn't cause an infinite loop" do
|
863
|
+
pending "This intermittently fails on JRuby" if RUBY_PLATFORM == 'java'
|
864
|
+
|
853
865
|
Object.any_instance.stub(:some_method)
|
854
866
|
o = Object.new
|
855
867
|
o.some_method
|
856
|
-
expect { o.dup.some_method }.to_not raise_error
|
868
|
+
expect { o.dup.some_method }.to_not raise_error
|
857
869
|
end
|
858
870
|
|
859
871
|
it "doesn't bomb if the object doesn't support `dup`" do
|
@@ -871,7 +883,7 @@ module RSpec
|
|
871
883
|
|
872
884
|
klass.any_instance
|
873
885
|
|
874
|
-
expect { klass.new.dup('Dup dup dup') }.to_not raise_error
|
886
|
+
expect { klass.new.dup('Dup dup dup') }.to_not raise_error
|
875
887
|
end
|
876
888
|
end
|
877
889
|
|
@@ -3,6 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe "AnyNumberOfTimes" do
|
4
4
|
before(:each) do
|
5
5
|
@mock = RSpec::Mocks::Mock.new("test mock")
|
6
|
+
allow(RSpec).to receive(:deprecate)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "is deprecated" do
|
10
|
+
expect(RSpec).to receive(:deprecate).with("any_number_of_times", :replacement => "stub")
|
11
|
+
expect(@mock).to receive(:random_call).any_number_of_times
|
6
12
|
end
|
7
13
|
|
8
14
|
it "passes if any number of times method is called many times" do
|
@@ -3,30 +3,28 @@ require 'spec_helper'
|
|
3
3
|
module RSpec
|
4
4
|
module Mocks
|
5
5
|
describe ArgumentListMatcher do
|
6
|
+
let(:argument_expectation) { RSpec::Mocks::ArgumentListMatcher.new }
|
7
|
+
let(:obj) { double("matcher") }
|
6
8
|
|
7
9
|
it "considers an object that responds to #matches? and #failure_message_for_should to be a matcher" do
|
8
|
-
|
9
|
-
obj
|
10
|
-
obj.stub(:respond_to?).with(:matches?).and_return(true)
|
11
|
-
obj.stub(:respond_to?).with(:failure_message_for_should).and_return(true)
|
10
|
+
obj.stub(:matches?)
|
11
|
+
obj.stub(:failure_message_for_should)
|
12
12
|
expect(argument_expectation.send(:is_matcher?, obj)).to be_true
|
13
13
|
end
|
14
14
|
|
15
15
|
it "considers an object that responds to #matches? and #failure_message to be a matcher for backward compatibility" do
|
16
|
-
|
17
|
-
obj
|
18
|
-
obj.stub(:respond_to?).with(:matches?).and_return(true)
|
19
|
-
obj.stub(:respond_to?).with(:failure_message_for_should).and_return(false)
|
20
|
-
obj.stub(:respond_to?).with(:failure_message).and_return(true)
|
16
|
+
obj.stub(:matches?)
|
17
|
+
obj.stub(:failure_message)
|
21
18
|
expect(argument_expectation.send(:is_matcher?, obj)).to be_true
|
22
19
|
end
|
23
20
|
|
24
21
|
it "does NOT consider an object that only responds to #matches? to be a matcher" do
|
25
|
-
|
26
|
-
obj
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
obj.stub(:matches?)
|
23
|
+
expect(argument_expectation.send(:is_matcher?, obj)).to be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not consider a null object to be a matcher" do
|
27
|
+
obj.as_null_object
|
30
28
|
expect(argument_expectation.send(:is_matcher?, obj)).to be_false
|
31
29
|
end
|
32
30
|
end
|