rspec-mocks 2.13.1 → 2.14.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Mocks
|
5
|
+
describe "Methods added to every object" do
|
6
|
+
include_context "with syntax", :expect
|
7
|
+
|
8
|
+
def added_methods
|
9
|
+
host = Class.new
|
10
|
+
orig_instance_methods = host.instance_methods
|
11
|
+
Syntax.enable_should(host)
|
12
|
+
(host.instance_methods - orig_instance_methods).map(&:to_sym)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'limits the number of methods that get added to all objects' do
|
16
|
+
# If really necessary, you can add to this list, but long term,
|
17
|
+
# we are hoping to cut down on the number of methods added to all objects
|
18
|
+
expect(added_methods).to match_array([
|
19
|
+
:as_null_object, :null_object?,
|
20
|
+
:received_message?, :should_not_receive, :should_receive,
|
21
|
+
:stub, :stub!, :stub_chain, :unstub, :unstub!
|
22
|
+
])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -5,7 +5,7 @@ module RSpec
|
|
5
5
|
|
6
6
|
describe "ordering" do
|
7
7
|
before { @double = double("test double") }
|
8
|
-
after { @double
|
8
|
+
after { reset @double }
|
9
9
|
|
10
10
|
it "passes when messages are received in order" do
|
11
11
|
@double.should_receive(:one).ordered
|
@@ -65,8 +65,8 @@ module RSpec
|
|
65
65
|
expect {
|
66
66
|
a.three
|
67
67
|
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
68
|
-
a
|
69
|
-
b
|
68
|
+
reset a
|
69
|
+
reset b
|
70
70
|
end
|
71
71
|
|
72
72
|
it "ignores order of non ordered messages" do
|
@@ -86,7 +86,7 @@ module RSpec
|
|
86
86
|
@double.ignored_2
|
87
87
|
@double.ordered_3
|
88
88
|
@double.ignored_1
|
89
|
-
@double
|
89
|
+
verify @double
|
90
90
|
end
|
91
91
|
|
92
92
|
it "supports duplicate messages" do
|
@@ -4,55 +4,110 @@ require 'rspec/mocks'
|
|
4
4
|
module RSpec
|
5
5
|
module Mocks
|
6
6
|
describe Space do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@verified
|
15
|
-
end
|
16
|
-
def rspec_reset
|
17
|
-
@reset = true
|
18
|
-
end
|
19
|
-
def reset?
|
20
|
-
@reset
|
21
|
-
end
|
22
|
-
end
|
23
|
-
@m1 = klazz.new
|
24
|
-
@m2 = klazz.new
|
7
|
+
let(:space) { RSpec::Mocks::Space.new }
|
8
|
+
let(:dbl_1) { Object.new }
|
9
|
+
let(:dbl_2) { Object.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
space.ensure_registered(dbl_1)
|
13
|
+
space.ensure_registered(dbl_2)
|
25
14
|
end
|
15
|
+
|
26
16
|
it "verifies all mocks within" do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
verifies = []
|
18
|
+
|
19
|
+
space.proxy_for(dbl_1).stub(:verify) { verifies << :dbl_1 }
|
20
|
+
space.proxy_for(dbl_2).stub(:verify) { verifies << :dbl_2 }
|
21
|
+
|
22
|
+
space.verify_all
|
23
|
+
|
24
|
+
expect(verifies).to match_array([:dbl_1, :dbl_2])
|
32
25
|
end
|
26
|
+
|
27
|
+
def define_singleton_method_on_recorder_for(klass, name, &block)
|
28
|
+
recorder = space.any_instance_recorder_for(klass)
|
29
|
+
(class << recorder; self; end).send(:define_method, name, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'verifies all any_instance recorders within' do
|
33
|
+
klass_1, klass_2 = Class.new, Class.new
|
34
|
+
|
35
|
+
verifies = []
|
36
|
+
|
37
|
+
# We can't `stub` a method on the recorder because it defines its own `stub`...
|
38
|
+
define_singleton_method_on_recorder_for(klass_1, :verify) { verifies << :klass_1 }
|
39
|
+
define_singleton_method_on_recorder_for(klass_2, :verify) { verifies << :klass_2 }
|
40
|
+
|
41
|
+
space.verify_all
|
42
|
+
|
43
|
+
expect(verifies).to match_array([:klass_1, :klass_2])
|
44
|
+
end
|
45
|
+
|
33
46
|
it "resets all mocks within" do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
47
|
+
resets = []
|
48
|
+
|
49
|
+
space.proxy_for(dbl_1).stub(:reset) { resets << :dbl_1 }
|
50
|
+
space.proxy_for(dbl_2).stub(:reset) { resets << :dbl_2 }
|
51
|
+
|
52
|
+
space.reset_all
|
53
|
+
|
54
|
+
expect(resets).to match_array([:dbl_1, :dbl_2])
|
39
55
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
56
|
+
|
57
|
+
it "does not leak mock proxies between examples" do
|
58
|
+
expect {
|
59
|
+
space.reset_all
|
60
|
+
}.to change { space.proxies.size }.to(0)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'does not leak any instance recorders between examples' do
|
64
|
+
space.any_instance_recorder_for(Class.new)
|
65
|
+
expect {
|
66
|
+
space.reset_all
|
67
|
+
}.to change { space.any_instance_recorders.size }.to(0)
|
44
68
|
end
|
69
|
+
|
45
70
|
it "resets the ordering" do
|
46
|
-
|
47
|
-
|
71
|
+
space.expectation_ordering.register :some_expectation
|
72
|
+
|
73
|
+
expect {
|
74
|
+
space.reset_all
|
75
|
+
}.to change { space.expectation_ordering.empty? }.from(false).to(true)
|
48
76
|
end
|
77
|
+
|
49
78
|
it "only adds an instance once" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
79
|
+
m1 = double("mock1")
|
80
|
+
|
81
|
+
expect {
|
82
|
+
space.ensure_registered(m1)
|
83
|
+
}.to change { space.proxies }
|
84
|
+
|
85
|
+
expect {
|
86
|
+
space.ensure_registered(m1)
|
87
|
+
}.not_to change { space.proxies }
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns a consistent any_instance_recorder for a given class' do
|
91
|
+
klass_1, klass_2 = Class.new, Class.new
|
92
|
+
|
93
|
+
r1 = space.any_instance_recorder_for(klass_1)
|
94
|
+
r2 = space.any_instance_recorder_for(klass_1)
|
95
|
+
r3 = space.any_instance_recorder_for(klass_2)
|
96
|
+
|
97
|
+
expect(r1).to be(r2)
|
98
|
+
expect(r1).not_to be(r3)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'removes an any_instance_recorder when requested' do
|
102
|
+
klass = Class.new
|
103
|
+
|
104
|
+
space.any_instance_recorder_for(klass)
|
105
|
+
|
106
|
+
expect {
|
107
|
+
space.remove_any_instance_recorder_for(klass)
|
108
|
+
}.to change { space.any_instance_recorders.size }.by(-1)
|
54
109
|
end
|
55
110
|
end
|
56
111
|
end
|
57
112
|
end
|
58
|
-
|
113
|
+
|
@@ -4,7 +4,7 @@ module RSpec
|
|
4
4
|
module Mocks
|
5
5
|
describe Mock do
|
6
6
|
before(:each) { @double = double("test double") }
|
7
|
-
after(:each) { @double
|
7
|
+
after(:each) { reset @double }
|
8
8
|
|
9
9
|
it "has method_missing as private" do
|
10
10
|
expect(RSpec::Mocks::Mock.private_instance_methods).to include_method(:method_missing)
|
@@ -17,7 +17,7 @@ module RSpec
|
|
17
17
|
it "reports line number of expectation of unreceived message" do
|
18
18
|
expected_error_line = __LINE__; @double.should_receive(:wont_happen).with("x", 3)
|
19
19
|
begin
|
20
|
-
@double
|
20
|
+
verify @double
|
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
|
@@ -29,7 +29,7 @@ module RSpec
|
|
29
29
|
@double.stub(:wont_happen)
|
30
30
|
expected_error_line = __LINE__; @double.should_receive(:wont_happen).with("x", 3)
|
31
31
|
begin
|
32
|
-
@double
|
32
|
+
verify @double
|
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
|
@@ -39,12 +39,11 @@ module RSpec
|
|
39
39
|
|
40
40
|
it "passes when not receiving message specified as not to be received" do
|
41
41
|
@double.should_not_receive(:not_expected)
|
42
|
-
@double
|
42
|
+
verify @double
|
43
43
|
end
|
44
44
|
|
45
45
|
it "warns when should_not_receive is followed by and_return" do
|
46
|
-
RSpec
|
47
|
-
with(/`and_return` with `should_not_receive` is deprecated/)
|
46
|
+
expect(RSpec).to receive(:deprecate).with("and_return with should_not_receive")
|
48
47
|
|
49
48
|
@double.should_not_receive(:do_something).and_return(1)
|
50
49
|
end
|
@@ -53,7 +52,7 @@ module RSpec
|
|
53
52
|
@double.should_not_receive(:message).with("unwanted text")
|
54
53
|
@double.should_receive(:message).with("other text")
|
55
54
|
@double.message "other text"
|
56
|
-
@double
|
55
|
+
verify @double
|
57
56
|
end
|
58
57
|
|
59
58
|
it "fails when receiving message specified as not to be received" do
|
@@ -63,7 +62,7 @@ module RSpec
|
|
63
62
|
violated
|
64
63
|
}.to raise_error(
|
65
64
|
RSpec::Mocks::MockExpectationError,
|
66
|
-
%Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
|
65
|
+
%Q|(Double "test double").not_expected(no args)\n expected: 0 times with any arguments\n received: 1 time|
|
67
66
|
)
|
68
67
|
end
|
69
68
|
|
@@ -74,39 +73,50 @@ module RSpec
|
|
74
73
|
violated
|
75
74
|
}.to raise_error(
|
76
75
|
RSpec::Mocks::MockExpectationError,
|
77
|
-
%Q|(Double "test double").not_expected("unexpected text")\n expected: 0 times\n received: 1 time|
|
76
|
+
%Q|(Double "test double").not_expected("unexpected text")\n expected: 0 times with arguments: ("unexpected text")\n received: 1 time with arguments: ("unexpected text")|
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "fails when array arguments do not match" do
|
81
|
+
@double.should_not_receive(:not_expected).with(["do not want"])
|
82
|
+
expect {
|
83
|
+
@double.not_expected(["do not want"])
|
84
|
+
violated
|
85
|
+
}.to raise_error(
|
86
|
+
RSpec::Mocks::MockExpectationError,
|
87
|
+
%Q|(Double "test double").not_expected(["do not want"])\n expected: 0 times with arguments: (["do not want"])\n received: 1 time with arguments: (["do not want"])|
|
78
88
|
)
|
79
89
|
end
|
80
90
|
|
81
91
|
it "passes when receiving message specified as not to be received with wrong args" do
|
82
92
|
@double.should_not_receive(:not_expected).with("unexpected text")
|
83
93
|
@double.not_expected "really unexpected text"
|
84
|
-
@double
|
94
|
+
verify @double
|
85
95
|
end
|
86
96
|
|
87
97
|
it "allows block to calculate return values" do
|
88
98
|
@double.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
|
89
99
|
expect(@double.something("a","b","c")).to eq "cba"
|
90
|
-
@double
|
100
|
+
verify @double
|
91
101
|
end
|
92
102
|
|
93
103
|
it "allows parameter as return value" do
|
94
104
|
@double.should_receive(:something).with("a","b","c").and_return("booh")
|
95
105
|
expect(@double.something("a","b","c")).to eq "booh"
|
96
|
-
@double
|
106
|
+
verify @double
|
97
107
|
end
|
98
108
|
|
99
109
|
it "returns the previously stubbed value if no return value is set" do
|
100
110
|
@double.stub(:something).with("a","b","c").and_return(:stubbed_value)
|
101
111
|
@double.should_receive(:something).with("a","b","c")
|
102
112
|
expect(@double.something("a","b","c")).to eq :stubbed_value
|
103
|
-
@double
|
113
|
+
verify @double
|
104
114
|
end
|
105
115
|
|
106
116
|
it "returns nil if no return value is set and there is no previously stubbed value" do
|
107
117
|
@double.should_receive(:something).with("a","b","c")
|
108
118
|
expect(@double.something("a","b","c")).to be_nil
|
109
|
-
@double
|
119
|
+
verify @double
|
110
120
|
end
|
111
121
|
|
112
122
|
it "raises exception if args don't match when method called" do
|
@@ -133,7 +143,7 @@ module RSpec
|
|
133
143
|
@double.should_receive(:something).with("a","b","c")
|
134
144
|
expect {
|
135
145
|
@double.something("a","d","c")
|
136
|
-
@double
|
146
|
+
verify @double
|
137
147
|
}.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
148
|
end
|
139
149
|
|
@@ -142,7 +152,7 @@ module RSpec
|
|
142
152
|
@double.should_receive(:something).with("a","b","c")
|
143
153
|
expect {
|
144
154
|
@double.something("a","d","c")
|
145
|
-
@double
|
155
|
+
verify @double
|
146
156
|
}.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
157
|
end
|
148
158
|
|
@@ -153,7 +163,7 @@ module RSpec
|
|
153
163
|
|
154
164
|
expect {
|
155
165
|
@double.method_with_default_argument(nil)
|
156
|
-
@double
|
166
|
+
verify @double
|
157
167
|
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :method_with_default_argument with unexpected arguments\n expected: ({})\n got: (nil)")
|
158
168
|
end
|
159
169
|
end
|
@@ -172,7 +182,7 @@ module RSpec
|
|
172
182
|
"booh"
|
173
183
|
end
|
174
184
|
expect(@double.something("a", "b")).to eq "booh"
|
175
|
-
@double
|
185
|
+
verify @double
|
176
186
|
end
|
177
187
|
|
178
188
|
it "fails if expectation block fails" do
|
@@ -185,6 +195,10 @@ module RSpec
|
|
185
195
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
186
196
|
end
|
187
197
|
|
198
|
+
it "is wrappable in an array" do
|
199
|
+
expect( Array(@double) ).to eq([@double])
|
200
|
+
end
|
201
|
+
|
188
202
|
context "with Ruby > 1.8.6", :unless => RUBY_VERSION.to_s == '1.8.6' do
|
189
203
|
it "passes proc to expectation block without an argument" do
|
190
204
|
# We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }
|
@@ -213,7 +227,7 @@ module RSpec
|
|
213
227
|
@double.should_receive(:not_expected).never
|
214
228
|
expect { @double.not_expected }.
|
215
229
|
to raise_error(RSpec::Mocks::MockExpectationError,
|
216
|
-
%Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
|
230
|
+
%Q|(Double "test double").not_expected(no args)\n expected: 0 times with any arguments\n received: 1 time|
|
217
231
|
)
|
218
232
|
end
|
219
233
|
|
@@ -282,7 +296,7 @@ module RSpec
|
|
282
296
|
@double.something 1
|
283
297
|
@double.something "a", 2
|
284
298
|
@double.something [], {}, "joe", 7
|
285
|
-
@double
|
299
|
+
verify @double
|
286
300
|
end
|
287
301
|
|
288
302
|
it "fails on no args if any args received" do
|
@@ -303,7 +317,7 @@ module RSpec
|
|
303
317
|
@double.stub(:method_that_yields).and_yield
|
304
318
|
value = @double.method_that_yields { :returned_obj }
|
305
319
|
expect(value).to eq :returned_obj
|
306
|
-
@double
|
320
|
+
verify @double
|
307
321
|
end
|
308
322
|
|
309
323
|
it "yields 0 args to blocks that take a variable number of arguments" do
|
@@ -311,7 +325,7 @@ module RSpec
|
|
311
325
|
a = nil
|
312
326
|
@double.yield_back {|*x| a = x}
|
313
327
|
expect(a).to eq []
|
314
|
-
@double
|
328
|
+
verify @double
|
315
329
|
end
|
316
330
|
|
317
331
|
it "yields 0 args multiple times to blocks that take a variable number of arguments" do
|
@@ -320,7 +334,7 @@ module RSpec
|
|
320
334
|
b = []
|
321
335
|
@double.yield_back {|*a| b << a}
|
322
336
|
expect(b).to eq [ [], [] ]
|
323
|
-
@double
|
337
|
+
verify @double
|
324
338
|
end
|
325
339
|
|
326
340
|
it "yields one arg to blocks that take a variable number of arguments" do
|
@@ -328,7 +342,7 @@ module RSpec
|
|
328
342
|
a = nil
|
329
343
|
@double.yield_back {|*x| a = x}
|
330
344
|
expect(a).to eq [99]
|
331
|
-
@double
|
345
|
+
verify @double
|
332
346
|
end
|
333
347
|
|
334
348
|
it "yields one arg 3 times consecutively to blocks that take a variable number of arguments" do
|
@@ -338,7 +352,7 @@ module RSpec
|
|
338
352
|
b = []
|
339
353
|
@double.yield_back {|*a| b << a}
|
340
354
|
expect(b).to eq [[99], [43], ["something fruity"]]
|
341
|
-
@double
|
355
|
+
verify @double
|
342
356
|
end
|
343
357
|
|
344
358
|
it "yields many args to blocks that take a variable number of arguments" do
|
@@ -346,7 +360,7 @@ module RSpec
|
|
346
360
|
a = nil
|
347
361
|
@double.yield_back {|*x| a = x}
|
348
362
|
expect(a).to eq [99, 27, "go"]
|
349
|
-
@double
|
363
|
+
verify @double
|
350
364
|
end
|
351
365
|
|
352
366
|
it "yields many args 3 times consecutively to blocks that take a variable number of arguments" do
|
@@ -356,7 +370,7 @@ module RSpec
|
|
356
370
|
b = []
|
357
371
|
@double.yield_back {|*a| b << a}
|
358
372
|
expect(b).to eq [[99, :green, "go"], ["wait", :amber], ["stop", 12, :red]]
|
359
|
-
@double
|
373
|
+
verify @double
|
360
374
|
end
|
361
375
|
|
362
376
|
it "yields single value" do
|
@@ -364,7 +378,7 @@ module RSpec
|
|
364
378
|
a = nil
|
365
379
|
@double.yield_back {|x| a = x}
|
366
380
|
expect(a).to eq 99
|
367
|
-
@double
|
381
|
+
verify @double
|
368
382
|
end
|
369
383
|
|
370
384
|
it "yields single value 3 times consecutively" do
|
@@ -374,7 +388,7 @@ module RSpec
|
|
374
388
|
b = []
|
375
389
|
@double.yield_back {|a| b << a}
|
376
390
|
expect(b).to eq [99, 43, "something fruity"]
|
377
|
-
@double
|
391
|
+
verify @double
|
378
392
|
end
|
379
393
|
|
380
394
|
it "yields two values" do
|
@@ -383,7 +397,7 @@ module RSpec
|
|
383
397
|
@double.yield_back {|x,y| a=x; b=y}
|
384
398
|
expect(a).to eq 'wha'
|
385
399
|
expect(b).to eq 'zup'
|
386
|
-
@double
|
400
|
+
verify @double
|
387
401
|
end
|
388
402
|
|
389
403
|
it "yields two values 3 times consecutively" do
|
@@ -393,7 +407,7 @@ module RSpec
|
|
393
407
|
c = []
|
394
408
|
@double.yield_back {|a,b| c << [a, b]}
|
395
409
|
expect(c).to eq [['wha', 'zup'], ['not', 'down'], [14, 65]]
|
396
|
-
@double
|
410
|
+
verify @double
|
397
411
|
end
|
398
412
|
|
399
413
|
it "fails when calling yielding method with wrong arity" do
|
@@ -423,7 +437,7 @@ module RSpec
|
|
423
437
|
it "is able to double send" do
|
424
438
|
@double.should_receive(:send).with(any_args)
|
425
439
|
@double.send 'hi'
|
426
|
-
@double
|
440
|
+
verify @double
|
427
441
|
end
|
428
442
|
|
429
443
|
it "is able to raise from method calling yielding double" do
|
@@ -435,13 +449,13 @@ module RSpec
|
|
435
449
|
end
|
436
450
|
}.to raise_error(StandardError, "Bang")
|
437
451
|
|
438
|
-
@double
|
452
|
+
verify @double
|
439
453
|
end
|
440
454
|
|
441
455
|
it "clears expectations after verify" do
|
442
456
|
@double.should_receive(:foobar)
|
443
457
|
@double.foobar
|
444
|
-
@double
|
458
|
+
verify @double
|
445
459
|
expect {
|
446
460
|
@double.foobar
|
447
461
|
}.to raise_error(RSpec::Mocks::MockExpectationError, %q|Double "test double" received unexpected message :foobar with (no args)|)
|
@@ -450,8 +464,8 @@ module RSpec
|
|
450
464
|
it "restores objects to their original state on rspec_reset" do
|
451
465
|
double = double("this is a double")
|
452
466
|
double.should_receive(:blah)
|
453
|
-
double
|
454
|
-
double
|
467
|
+
reset double
|
468
|
+
verify double #should throw if reset didn't work
|
455
469
|
end
|
456
470
|
|
457
471
|
it "works even after method_missing starts raising NameErrors instead of NoMethodErrors" do
|
@@ -477,9 +491,8 @@ module RSpec
|
|
477
491
|
|
478
492
|
@double.should_receive(:foobar)
|
479
493
|
@double.foobar
|
480
|
-
@double
|
494
|
+
verify @double
|
481
495
|
|
482
|
-
expect { @double.foobar }.to_not raise_error(NameError)
|
483
496
|
expect { @double.foobar }.to raise_error(RSpec::Mocks::MockExpectationError)
|
484
497
|
end
|
485
498
|
|
@@ -489,7 +502,7 @@ module RSpec
|
|
489
502
|
expect(@double.msg(:arg)).to equal(:double_value)
|
490
503
|
expect(@double.msg).to equal(:stub_value)
|
491
504
|
expect(@double.msg).to equal(:stub_value)
|
492
|
-
@double
|
505
|
+
verify @double
|
493
506
|
end
|
494
507
|
|
495
508
|
it "does not require a different signature to replace a method stub" do
|
@@ -498,7 +511,7 @@ module RSpec
|
|
498
511
|
expect(@double.msg(:arg)).to equal(:double_value)
|
499
512
|
expect(@double.msg).to equal(:stub_value)
|
500
513
|
expect(@double.msg).to equal(:stub_value)
|
501
|
-
@double
|
514
|
+
verify @double
|
502
515
|
end
|
503
516
|
|
504
517
|
it "raises an error when a previously stubbed method has a negative expectation" do
|
@@ -514,21 +527,21 @@ module RSpec
|
|
514
527
|
expect(non_double.msg(:arg)).to equal(:double_value)
|
515
528
|
expect(non_double.msg).to equal(:stub_value)
|
516
529
|
expect(non_double.msg).to equal(:stub_value)
|
517
|
-
non_double
|
530
|
+
verify non_double
|
518
531
|
end
|
519
532
|
|
520
533
|
it "returns the stubbed value when no new value specified" do
|
521
534
|
@double.stub(:msg).and_return(:stub_value)
|
522
535
|
@double.should_receive(:msg)
|
523
536
|
expect(@double.msg).to equal(:stub_value)
|
524
|
-
@double
|
537
|
+
verify @double
|
525
538
|
end
|
526
539
|
|
527
540
|
it "returns the stubbed value when stubbed with args and no new value specified" do
|
528
541
|
@double.stub(:msg).with(:arg).and_return(:stub_value)
|
529
542
|
@double.should_receive(:msg).with(:arg)
|
530
543
|
expect(@double.msg(:arg)).to equal(:stub_value)
|
531
|
-
@double
|
544
|
+
verify @double
|
532
545
|
end
|
533
546
|
|
534
547
|
it "does not mess with the stub's yielded values when also doubleed" do
|
@@ -536,7 +549,7 @@ module RSpec
|
|
536
549
|
@double.should_receive(:yield_back).and_yield(:double_value)
|
537
550
|
@double.yield_back{|v| expect(v).to eq :double_value }
|
538
551
|
@double.yield_back{|v| expect(v).to eq :stub_value }
|
539
|
-
@double
|
552
|
+
verify @double
|
540
553
|
end
|
541
554
|
|
542
555
|
it "can yield multiple times when told to do so" do
|
@@ -546,7 +559,7 @@ module RSpec
|
|
546
559
|
expect { |b| @double.foo(&b) }.to yield_successive_args(:first_yield, :second_yield)
|
547
560
|
expect { |b| @double.foo(&b) }.to yield_with_args(:stub_value)
|
548
561
|
|
549
|
-
@double
|
562
|
+
verify @double
|
550
563
|
end
|
551
564
|
|
552
565
|
it "assigns stub return values" do
|
@@ -609,6 +622,8 @@ module RSpec
|
|
609
622
|
end
|
610
623
|
|
611
624
|
it "calls the block after #any_number_of_times" do
|
625
|
+
expect(RSpec).to receive(:deprecate).with("any_number_of_times", :replacement => "stub")
|
626
|
+
|
612
627
|
@double.should_receive(:foo).any_number_of_times { add_call }
|
613
628
|
|
614
629
|
(1..7).each { @double.foo }
|
@@ -681,7 +696,7 @@ module RSpec
|
|
681
696
|
expect do
|
682
697
|
@double.foo('baz')
|
683
698
|
end.to raise_error
|
684
|
-
@double
|
699
|
+
reset @double
|
685
700
|
end
|
686
701
|
end
|
687
702
|
|
@@ -693,7 +708,7 @@ module RSpec
|
|
693
708
|
expect do
|
694
709
|
@double.foo(d2)
|
695
710
|
end.to raise_error
|
696
|
-
@double
|
711
|
+
reset @double
|
697
712
|
end
|
698
713
|
end
|
699
714
|
|
@@ -705,7 +720,7 @@ module RSpec
|
|
705
720
|
expect do
|
706
721
|
@double.foo(d2)
|
707
722
|
end.to raise_error
|
708
|
-
@double
|
723
|
+
reset @double
|
709
724
|
end
|
710
725
|
end
|
711
726
|
end
|
@@ -724,11 +739,11 @@ module RSpec
|
|
724
739
|
expect do
|
725
740
|
expect(@double.foo('wrong')).to eq('baz')
|
726
741
|
end.to raise_error(/received :foo with unexpected arguments/)
|
727
|
-
@double
|
742
|
+
reset @double
|
728
743
|
end
|
729
744
|
end
|
730
745
|
end
|
731
746
|
end
|
732
|
-
|
733
747
|
end
|
734
748
|
end
|
749
|
+
|