rspec-mocks 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +104 -36
- data/README.md +35 -4
- data/lib/rspec/mocks.rb +52 -13
- data/lib/rspec/mocks/any_instance.rb +10 -0
- data/lib/rspec/mocks/any_instance/chain.rb +17 -0
- data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +1 -1
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +9 -6
- data/lib/rspec/mocks/any_instance/message_chains.rb +10 -1
- data/lib/rspec/mocks/any_instance/proxy.rb +112 -0
- data/lib/rspec/mocks/any_instance/recorder.rb +49 -18
- data/lib/rspec/mocks/any_instance/stub_chain.rb +5 -3
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +1 -1
- data/lib/rspec/mocks/argument_list_matcher.rb +5 -3
- data/lib/rspec/mocks/argument_matchers.rb +28 -12
- data/lib/rspec/mocks/configuration.rb +29 -0
- data/lib/rspec/mocks/error_generator.rb +2 -5
- data/lib/rspec/mocks/example_methods.rb +122 -13
- data/lib/rspec/mocks/instance_method_stasher.rb +26 -2
- data/lib/rspec/mocks/marshal_extension.rb +41 -0
- data/lib/rspec/mocks/matchers/expectation_customization.rb +20 -0
- data/lib/rspec/mocks/matchers/receive.rb +6 -20
- data/lib/rspec/mocks/matchers/receive_message_chain.rb +7 -5
- data/lib/rspec/mocks/matchers/receive_messages.rb +1 -2
- data/lib/rspec/mocks/message_chain.rb +9 -9
- data/lib/rspec/mocks/message_expectation.rb +6 -5
- data/lib/rspec/mocks/method_double.rb +67 -10
- data/lib/rspec/mocks/method_reference.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +10 -14
- data/lib/rspec/mocks/object_reference.rb +7 -4
- data/lib/rspec/mocks/proxy.rb +95 -8
- data/lib/rspec/mocks/space.rb +58 -9
- data/lib/rspec/mocks/syntax.rb +128 -210
- data/lib/rspec/mocks/targets.rb +6 -8
- data/lib/rspec/mocks/test_double.rb +16 -25
- data/lib/rspec/mocks/verifying_double.rb +15 -12
- data/lib/rspec/mocks/verifying_message_expecation.rb +3 -3
- data/lib/rspec/mocks/verifying_proxy.rb +23 -17
- data/lib/rspec/mocks/version.rb +3 -1
- metadata +29 -257
- metadata.gz.sig +0 -0
- data/features/README.md +0 -75
- data/features/Scope.md +0 -17
- data/features/Upgrade.md +0 -22
- data/features/argument_matchers/README.md +0 -27
- data/features/argument_matchers/explicit.feature +0 -59
- data/features/argument_matchers/general_matchers.feature +0 -85
- data/features/argument_matchers/type_matchers.feature +0 -26
- data/features/message_expectations/README.md +0 -75
- data/features/message_expectations/allow_any_instance_of.feature +0 -26
- data/features/message_expectations/any_instance.feature +0 -43
- data/features/message_expectations/block_local_expectations.feature.pending +0 -55
- data/features/message_expectations/call_original.feature +0 -23
- data/features/message_expectations/expect_message_using_expect.feature +0 -107
- data/features/message_expectations/expect_message_using_should_receive.feature +0 -118
- data/features/message_expectations/message_chains_using_expect.feature +0 -49
- data/features/message_expectations/receive_counts.feature +0 -209
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +0 -50
- data/features/method_stubs/README.md +0 -77
- data/features/method_stubs/allow_any_instance_of.feature +0 -136
- data/features/method_stubs/as_null_object.feature +0 -40
- data/features/method_stubs/receive_message_chain.feature +0 -51
- data/features/method_stubs/simple_return_value_with_allow.feature +0 -44
- data/features/method_stubs/simple_return_value_with_stub.feature +0 -64
- data/features/method_stubs/stub_implementation.feature +0 -48
- data/features/method_stubs/to_ary.feature +0 -51
- data/features/mutating_constants/README.md +0 -82
- data/features/mutating_constants/hiding_defined_constant.feature +0 -64
- data/features/mutating_constants/stub_defined_constant.feature +0 -78
- data/features/mutating_constants/stub_undefined_constant.feature +0 -50
- data/features/outside_rspec/standalone.feature +0 -33
- data/features/spies/spy_partial_mock_method.feature +0 -34
- data/features/spies/spy_pure_mock_method.feature +0 -76
- data/features/spies/spy_unstubbed_method.feature +0 -18
- data/features/step_definitions/additional_cli_steps.rb +0 -11
- data/features/support/env.rb +0 -22
- data/features/support/rubinius.rb +0 -6
- data/features/test_frameworks/test_unit.feature +0 -54
- data/features/verifying_doubles/README.md +0 -17
- data/features/verifying_doubles/class_doubles.feature +0 -73
- data/features/verifying_doubles/dynamic_classes.feature +0 -71
- data/features/verifying_doubles/instance_doubles.feature +0 -103
- data/features/verifying_doubles/object_doubles.feature +0 -65
- data/features/verifying_doubles/partial_doubles.feature +0 -34
- data/lib/rspec/mocks/extensions/marshal.rb +0 -17
- data/lib/rspec/mocks/framework.rb +0 -35
- data/lib/rspec/mocks/method_signature_verifier.rb +0 -207
- data/lib/rspec/mocks/ruby_features.rb +0 -24
- data/spec/rspec/mocks/and_call_original_spec.rb +0 -268
- data/spec/rspec/mocks/and_return_spec.rb +0 -23
- data/spec/rspec/mocks/and_yield_spec.rb +0 -126
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +0 -41
- data/spec/rspec/mocks/any_instance_spec.rb +0 -1045
- data/spec/rspec/mocks/array_including_matcher_spec.rb +0 -41
- data/spec/rspec/mocks/at_least_spec.rb +0 -123
- data/spec/rspec/mocks/at_most_spec.rb +0 -90
- data/spec/rspec/mocks/before_all_spec.rb +0 -132
- data/spec/rspec/mocks/block_return_value_spec.rb +0 -70
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +0 -204
- data/spec/rspec/mocks/configuration_spec.rb +0 -242
- data/spec/rspec/mocks/double_spec.rb +0 -874
- data/spec/rspec/mocks/example_methods_spec.rb +0 -13
- data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -54
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +0 -184
- data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +0 -67
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +0 -94
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +0 -74
- data/spec/rspec/mocks/matchers/have_received_spec.rb +0 -347
- data/spec/rspec/mocks/matchers/receive_message_chain_spec.rb +0 -198
- data/spec/rspec/mocks/matchers/receive_messages_spec.rb +0 -140
- data/spec/rspec/mocks/matchers/receive_spec.rb +0 -418
- data/spec/rspec/mocks/method_signature_verifier_spec.rb +0 -272
- data/spec/rspec/mocks/methods_spec.rb +0 -26
- data/spec/rspec/mocks/mock_expectation_error_spec.rb +0 -22
- data/spec/rspec/mocks/mock_ordering_spec.rb +0 -114
- data/spec/rspec/mocks/multiple_return_value_spec.rb +0 -132
- data/spec/rspec/mocks/mutate_const_spec.rb +0 -542
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +0 -52
- data/spec/rspec/mocks/null_object_mock_spec.rb +0 -133
- data/spec/rspec/mocks/once_counts_spec.rb +0 -52
- data/spec/rspec/mocks/options_hash_spec.rb +0 -35
- data/spec/rspec/mocks/order_group_spec.rb +0 -27
- data/spec/rspec/mocks/partial_double_spec.rb +0 -308
- data/spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb +0 -95
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +0 -145
- data/spec/rspec/mocks/precise_counts_spec.rb +0 -68
- data/spec/rspec/mocks/record_messages_spec.rb +0 -26
- data/spec/rspec/mocks/serialization_spec.rb +0 -90
- data/spec/rspec/mocks/space_spec.rb +0 -244
- data/spec/rspec/mocks/stash_spec.rb +0 -46
- data/spec/rspec/mocks/stub_chain_spec.rb +0 -168
- data/spec/rspec/mocks/stub_implementation_spec.rb +0 -81
- data/spec/rspec/mocks/stub_spec.rb +0 -327
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +0 -58
- data/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +0 -101
- data/spec/rspec/mocks/syntax_spec.rb +0 -19
- data/spec/rspec/mocks/test_double_spec.rb +0 -49
- data/spec/rspec/mocks/to_ary_spec.rb +0 -54
- data/spec/rspec/mocks/twice_counts_spec.rb +0 -66
- data/spec/rspec/mocks/verifying_double_spec.rb +0 -590
- data/spec/rspec/mocks/verifying_message_expecation_spec.rb +0 -69
- data/spec/rspec/mocks_spec.rb +0 -192
- data/spec/spec_helper.rb +0 -121
@@ -1,272 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe MethodSignatureVerifier do
|
6
|
-
describe '#verify!' do
|
7
|
-
let(:signature) { MethodSignature.new(test_method) }
|
8
|
-
|
9
|
-
def valid_non_kw_args?(arity)
|
10
|
-
described_class.new(signature, [nil] * arity).valid?
|
11
|
-
end
|
12
|
-
|
13
|
-
def valid?(*args)
|
14
|
-
described_class.new(signature, args).valid?
|
15
|
-
end
|
16
|
-
|
17
|
-
def error_description
|
18
|
-
described_class.new(signature, []).error_message[/Expected (.*),/, 1]
|
19
|
-
end
|
20
|
-
|
21
|
-
def error_for(*args)
|
22
|
-
described_class.new(signature, args).error_message
|
23
|
-
end
|
24
|
-
|
25
|
-
def signature_description
|
26
|
-
signature.description
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'with a method with arguments' do
|
30
|
-
def arity_two(x, y); end
|
31
|
-
|
32
|
-
let(:test_method) { method(:arity_two) }
|
33
|
-
|
34
|
-
it 'covers only the exact arity' do
|
35
|
-
expect(valid_non_kw_args?(1)).to eq(false)
|
36
|
-
expect(valid_non_kw_args?(2)).to eq(true)
|
37
|
-
expect(valid_non_kw_args?(3)).to eq(false)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'does not treat a last-arg hash as kw args' do
|
41
|
-
expect(valid?(1, {})).to eq(true)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'describes the arity precisely' do
|
45
|
-
expect(error_description).to eq("2")
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'mentions only the arity in the description' do
|
49
|
-
expect(signature_description).to eq("arity of 2")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'a method with splat arguments' do
|
54
|
-
def arity_splat(_, *); end
|
55
|
-
|
56
|
-
let(:test_method) { method(:arity_splat) }
|
57
|
-
|
58
|
-
it 'covers a range from the lower bound upwards' do
|
59
|
-
expect(valid_non_kw_args?(0)).to eq(false)
|
60
|
-
expect(valid_non_kw_args?(1)).to eq(true)
|
61
|
-
expect(valid_non_kw_args?(2)).to eq(true)
|
62
|
-
expect(valid_non_kw_args?(3)).to eq(true)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'describes the arity with no upper bound' do
|
66
|
-
expect(error_description).to eq("1 or more")
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'mentions only the arity in the description' do
|
70
|
-
expect(signature_description).to eq("arity of 1 or more")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'a method with optional arguments' do
|
75
|
-
def arity_optional(x, y, z = 1); end
|
76
|
-
|
77
|
-
let(:test_method) { method(:arity_optional) }
|
78
|
-
|
79
|
-
it 'covers a range from min to max possible arguments' do
|
80
|
-
expect(valid_non_kw_args?(1)).to eq(false)
|
81
|
-
expect(valid_non_kw_args?(2)).to eq(true)
|
82
|
-
expect(valid_non_kw_args?(3)).to eq(true)
|
83
|
-
|
84
|
-
if optional_and_splat_args_supported?
|
85
|
-
expect(valid_non_kw_args?(4)).to eq(false)
|
86
|
-
else
|
87
|
-
expect(valid_non_kw_args?(4)).to eq(true)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
if optional_and_splat_args_supported?
|
92
|
-
it 'describes the arity as a range' do
|
93
|
-
expect(error_description).to eq("2 to 3")
|
94
|
-
end
|
95
|
-
else
|
96
|
-
it 'describes the arity with no upper bound' do
|
97
|
-
expect(error_description).to eq("2 or more")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
if kw_args_supported?
|
103
|
-
describe 'a method with optional keyword arguments' do
|
104
|
-
eval <<-RUBY
|
105
|
-
def arity_kw(x, y:1, z:2); end
|
106
|
-
RUBY
|
107
|
-
|
108
|
-
let(:test_method) { method(:arity_kw) }
|
109
|
-
|
110
|
-
it 'does not require any of the arguments' do
|
111
|
-
expect(valid?(nil)).to eq(true)
|
112
|
-
expect(valid?(nil, nil)).to eq(false)
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'does not allow an invalid keyword arguments' do
|
116
|
-
expect(valid?(nil, :a => 1)).to eq(false)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'mentions the invalid keyword args in the error' do
|
120
|
-
expect(error_for(nil, :a => 0, :b => 1)).to \
|
121
|
-
eq("Invalid keyword arguments provided: a, b")
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'describes invalid arity precisely' do
|
125
|
-
expect(error_for()).to \
|
126
|
-
eq("Wrong number of arguments. Expected 1, got 0.")
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'does not blow up when given a BasicObject as the last arg' do
|
130
|
-
expect(valid?(BasicObject.new)).to eq(true)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'does not mutate the provided args array' do
|
134
|
-
args = [nil, { :y => 1 }]
|
135
|
-
described_class.new(signature, args).valid?
|
136
|
-
expect(args).to eq([nil, { :y => 1 }])
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'mentions the arity and optional kw args in the description' do
|
140
|
-
expect(signature_description).to eq("arity of 1 and optional keyword args (:y, :z)")
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
if required_kw_args_supported?
|
146
|
-
describe 'a method with required keyword arguments' do
|
147
|
-
eval <<-RUBY
|
148
|
-
def arity_required_kw(x, y:, z:, a: 'default'); end
|
149
|
-
RUBY
|
150
|
-
|
151
|
-
let(:test_method) { method(:arity_required_kw) }
|
152
|
-
|
153
|
-
it 'returns false unless all required keywords args are present' do
|
154
|
-
expect(valid?(nil, :a => 0, :y => 1, :z => 2)).to eq(true)
|
155
|
-
expect(valid?(nil, :a => 0, :y => 1)).to eq(false)
|
156
|
-
expect(valid?(nil, nil, :a => 0, :y => 1, :z => 2)).to eq(false)
|
157
|
-
expect(valid?(nil, nil)).to eq(false)
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'mentions the missing required keyword args in the error' do
|
161
|
-
expect(error_for(nil, :a => 0)).to \
|
162
|
-
eq("Missing required keyword arguments: y, z")
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'is described precisely when arity is wrong' do
|
166
|
-
expect(error_for(nil, nil, :z => 0, :y => 1)).to \
|
167
|
-
eq("Wrong number of arguments. Expected 1, got 2.")
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'mentions the arity, optional kw args and required kw args in the description' do
|
171
|
-
expect(signature_description).to \
|
172
|
-
eq("arity of 1 and optional keyword args (:a) and required keyword args (:y, :z)")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe 'a method with required keyword arguments and a splat' do
|
177
|
-
eval <<-RUBY
|
178
|
-
def arity_required_kw_splat(w, *x, y:, z:, a: 'default'); end
|
179
|
-
RUBY
|
180
|
-
|
181
|
-
let(:test_method) { method(:arity_required_kw_splat) }
|
182
|
-
|
183
|
-
it 'returns false unless all required keywords args are present' do
|
184
|
-
expect(valid?(nil, :a => 0, :y => 1, :z => 2)).to eq(true)
|
185
|
-
expect(valid?(nil, :a => 0, :y => 1)).to eq(false)
|
186
|
-
expect(valid?(nil, nil, :a => 0, :y => 1, :z => 2)).to eq(true)
|
187
|
-
expect(valid?(nil, nil, nil)).to eq(false)
|
188
|
-
expect(valid?).to eq(false)
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'mentions missing required keyword args in the error' do
|
192
|
-
expect(error_for(nil, :y => 1)).to \
|
193
|
-
eq("Missing required keyword arguments: z")
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'mentions the arity, optional kw args and required kw args in the description' do
|
197
|
-
expect(signature_description).to \
|
198
|
-
eq("arity of 1 or more and optional keyword args (:a) and required keyword args (:y, :z)")
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe 'a method with required keyword arguments and a keyword arg splat' do
|
203
|
-
eval <<-RUBY
|
204
|
-
def arity_kw_arg_splat(x:, **rest); end
|
205
|
-
RUBY
|
206
|
-
|
207
|
-
let(:test_method) { method(:arity_kw_arg_splat) }
|
208
|
-
|
209
|
-
it 'allows extra undeclared keyword args' do
|
210
|
-
expect(valid?(:x => 1)).to eq(true)
|
211
|
-
expect(valid?(:x => 1, :y => 2)).to eq(true)
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'mentions missing required keyword args in the error' do
|
215
|
-
expect(error_for(:y => 1)).to \
|
216
|
-
eq("Missing required keyword arguments: x")
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'mentions the required kw args and keyword splat in the description' do
|
220
|
-
expect(signature_description).to \
|
221
|
-
eq("required keyword args (:x) and any additional keyword args")
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe 'a method with a required arg and a keyword arg splat' do
|
226
|
-
eval <<-RUBY
|
227
|
-
def arity_kw_arg_splat(x, **rest); end
|
228
|
-
RUBY
|
229
|
-
|
230
|
-
let(:test_method) { method(:arity_kw_arg_splat) }
|
231
|
-
|
232
|
-
it 'allows a single arg and any number of keyword args' do
|
233
|
-
expect(valid?(nil)).to eq(true)
|
234
|
-
expect(valid?(nil, :x => 1)).to eq(true)
|
235
|
-
expect(valid?(nil, :x => 1, :y => 2)).to eq(true)
|
236
|
-
expect(valid?(:x => 1)).to eq(true)
|
237
|
-
|
238
|
-
expect(valid?).to eq(false)
|
239
|
-
expect(valid?(nil, nil)).to eq(false)
|
240
|
-
expect(valid?(nil, nil, :x => 1)).to eq(false)
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'describes the arity precisely' do
|
244
|
-
expect(error_for()).to \
|
245
|
-
eq("Wrong number of arguments. Expected 1, got 0.")
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'mentions the required kw args and keyword splat in the description' do
|
249
|
-
expect(signature_description).to \
|
250
|
-
eq("arity of 1 and any additional keyword args")
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe 'a method with a block' do
|
256
|
-
def arity_block(_, &block); end
|
257
|
-
|
258
|
-
let(:test_method) { method(:arity_block) }
|
259
|
-
|
260
|
-
it 'does not count the block as a parameter' do
|
261
|
-
expect(valid_non_kw_args?(1)).to eq(true)
|
262
|
-
expect(valid_non_kw_args?(2)).to eq(false)
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'describes the arity precisely' do
|
266
|
-
expect(error_description).to eq("1")
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
@@ -1,26 +0,0 @@
|
|
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_chain, :unstub
|
22
|
-
])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe 'MockExpectationError' do
|
6
|
-
|
7
|
-
class Foo
|
8
|
-
def self.foo
|
9
|
-
bar
|
10
|
-
rescue StandardError
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'is not caught by StandardError rescue blocks' do
|
15
|
-
expect(Foo).not_to receive(:bar)
|
16
|
-
expect {
|
17
|
-
Foo.foo
|
18
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
|
6
|
-
describe "ordering" do
|
7
|
-
before { @double = double("test double") }
|
8
|
-
after { reset @double }
|
9
|
-
|
10
|
-
it "passes when messages are received in order" do
|
11
|
-
@double.should_receive(:one).ordered
|
12
|
-
@double.should_receive(:two).ordered
|
13
|
-
@double.should_receive(:three).ordered
|
14
|
-
@double.one
|
15
|
-
@double.two
|
16
|
-
@double.three
|
17
|
-
end
|
18
|
-
|
19
|
-
it "passes when messages are received in order" do
|
20
|
-
@double.stub(:something)
|
21
|
-
@double.should_receive(:one).ordered
|
22
|
-
@double.should_receive(:two).ordered
|
23
|
-
@double.should_receive(:three).at_least(:once).ordered
|
24
|
-
@double.one
|
25
|
-
@double.two
|
26
|
-
@double.three
|
27
|
-
@double.three
|
28
|
-
end
|
29
|
-
|
30
|
-
it "passes when messages are received in order across objects" do
|
31
|
-
a = double("a")
|
32
|
-
b = double("b")
|
33
|
-
a.should_receive(:one).ordered
|
34
|
-
b.should_receive(:two).ordered
|
35
|
-
a.should_receive(:three).ordered
|
36
|
-
a.one
|
37
|
-
b.two
|
38
|
-
a.three
|
39
|
-
end
|
40
|
-
|
41
|
-
it "fails when messages are received out of order (2nd message 1st)" do
|
42
|
-
@double.should_receive(:one).ordered
|
43
|
-
@double.should_receive(:two).ordered
|
44
|
-
expect {
|
45
|
-
@double.two
|
46
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :two out of order")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "fails when messages are received out of order (3rd message 1st)" do
|
50
|
-
@double.should_receive(:one).ordered
|
51
|
-
@double.should_receive(:two).ordered
|
52
|
-
@double.should_receive(:three).ordered
|
53
|
-
@double.one
|
54
|
-
expect {
|
55
|
-
@double.three
|
56
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "fails when messages are received out of order (3rd message 2nd)" do
|
60
|
-
@double.should_receive(:one).ordered
|
61
|
-
@double.should_receive(:two).ordered
|
62
|
-
@double.should_receive(:three).ordered
|
63
|
-
@double.one
|
64
|
-
expect {
|
65
|
-
@double.three
|
66
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
67
|
-
end
|
68
|
-
|
69
|
-
it "fails when messages are out of order across objects" do
|
70
|
-
a = double("test double")
|
71
|
-
b = double("another test double")
|
72
|
-
a.should_receive(:one).ordered
|
73
|
-
b.should_receive(:two).ordered
|
74
|
-
a.should_receive(:three).ordered
|
75
|
-
a.one
|
76
|
-
expect {
|
77
|
-
a.three
|
78
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
79
|
-
reset a
|
80
|
-
reset b
|
81
|
-
end
|
82
|
-
|
83
|
-
it "ignores order of non ordered messages" do
|
84
|
-
@double.should_receive(:ignored_0)
|
85
|
-
@double.should_receive(:ordered_1).ordered
|
86
|
-
@double.should_receive(:ignored_1)
|
87
|
-
@double.should_receive(:ordered_2).ordered
|
88
|
-
@double.should_receive(:ignored_2)
|
89
|
-
@double.should_receive(:ignored_3)
|
90
|
-
@double.should_receive(:ordered_3).ordered
|
91
|
-
@double.should_receive(:ignored_4)
|
92
|
-
@double.ignored_3
|
93
|
-
@double.ordered_1
|
94
|
-
@double.ignored_0
|
95
|
-
@double.ordered_2
|
96
|
-
@double.ignored_4
|
97
|
-
@double.ignored_2
|
98
|
-
@double.ordered_3
|
99
|
-
@double.ignored_1
|
100
|
-
verify @double
|
101
|
-
end
|
102
|
-
|
103
|
-
it "supports duplicate messages" do
|
104
|
-
@double.should_receive(:a).ordered
|
105
|
-
@double.should_receive(:b).ordered
|
106
|
-
@double.should_receive(:a).ordered
|
107
|
-
|
108
|
-
@double.a
|
109
|
-
@double.b
|
110
|
-
@double.a
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "a double stubbed with multiple return values" do
|
6
|
-
let(:a_double) { double }
|
7
|
-
|
8
|
-
before do
|
9
|
-
a_double.stub(:foo).and_return(:val_1, nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can still set a message expectation with a single return value' do
|
13
|
-
a_double.should_receive(:foo).once.and_return(:val_1)
|
14
|
-
expect(a_double.foo).to eq(:val_1)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "a message expectation with multiple return values and no specified count" do
|
19
|
-
before(:each) do
|
20
|
-
@double = double
|
21
|
-
@return_values = [1,2,3]
|
22
|
-
@double.should_receive(:do_something).and_return(@return_values[0],@return_values[1],@return_values[2])
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns values in order" do
|
26
|
-
expect(@double.do_something).to eq @return_values[0]
|
27
|
-
expect(@double.do_something).to eq @return_values[1]
|
28
|
-
expect(@double.do_something).to eq @return_values[2]
|
29
|
-
verify @double
|
30
|
-
end
|
31
|
-
|
32
|
-
it "falls back to a previously stubbed value" do
|
33
|
-
@double.stub :do_something => :stub_result
|
34
|
-
expect(@double.do_something).to eq @return_values[0]
|
35
|
-
expect(@double.do_something).to eq @return_values[1]
|
36
|
-
expect(@double.do_something).to eq @return_values[2]
|
37
|
-
expect(@double.do_something).to eq :stub_result
|
38
|
-
end
|
39
|
-
|
40
|
-
it "fails when there are too few calls (if there is no stub)" do
|
41
|
-
@double.do_something
|
42
|
-
@double.do_something
|
43
|
-
expect { verify @double }.to raise_error
|
44
|
-
end
|
45
|
-
|
46
|
-
it "fails when there are too many calls (if there is no stub)" do
|
47
|
-
@double.do_something
|
48
|
-
@double.do_something
|
49
|
-
@double.do_something
|
50
|
-
@double.do_something
|
51
|
-
expect { verify @double }.to raise_error
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "a message expectation with multiple return values with a specified count equal to the number of values" do
|
56
|
-
before(:each) do
|
57
|
-
@double = double
|
58
|
-
@return_values = [1,2,3]
|
59
|
-
@double.should_receive(:do_something).exactly(3).times.and_return(@return_values[0], @return_values[1], @return_values[2])
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns values in order to consecutive calls" do
|
63
|
-
expect(@double.do_something).to eq @return_values[0]
|
64
|
-
expect(@double.do_something).to eq @return_values[1]
|
65
|
-
expect(@double.do_something).to eq @return_values[2]
|
66
|
-
verify @double
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "a message expectation with multiple return values specifying at_least less than the number of values" do
|
71
|
-
before(:each) do
|
72
|
-
@double = double
|
73
|
-
@double.should_receive(:do_something).at_least(:twice).with(no_args).and_return(11, 22)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "uses the last return value for subsequent calls" do
|
77
|
-
expect(@double.do_something).to equal(11)
|
78
|
-
expect(@double.do_something).to equal(22)
|
79
|
-
expect(@double.do_something).to equal(22)
|
80
|
-
verify @double
|
81
|
-
end
|
82
|
-
|
83
|
-
it "fails when called less than the specified number" do
|
84
|
-
expect(@double.do_something).to equal(11)
|
85
|
-
expect { verify @double }.to raise_error(RSpec::Mocks::MockExpectationError)
|
86
|
-
end
|
87
|
-
|
88
|
-
context "when method is stubbed too" do
|
89
|
-
before { @double.stub(:do_something).and_return :stub_result }
|
90
|
-
|
91
|
-
it "uses the last value for subsequent calls" do
|
92
|
-
expect(@double.do_something).to equal(11)
|
93
|
-
expect(@double.do_something).to equal(22)
|
94
|
-
expect(@double.do_something).to equal(22)
|
95
|
-
verify @double
|
96
|
-
end
|
97
|
-
|
98
|
-
it "fails when called less than the specified number" do
|
99
|
-
expect(@double.do_something).to equal(11)
|
100
|
-
expect { verify @double }.to raise_error(RSpec::Mocks::MockExpectationError)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "a message expectation with multiple return values with a specified count larger than the number of values" do
|
106
|
-
before(:each) do
|
107
|
-
@double = RSpec::Mocks::Double.new("double")
|
108
|
-
@double.should_receive(:do_something).exactly(3).times.and_return(11, 22)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "uses the last return value for subsequent calls" do
|
112
|
-
expect(@double.do_something).to equal(11)
|
113
|
-
expect(@double.do_something).to equal(22)
|
114
|
-
expect(@double.do_something).to equal(22)
|
115
|
-
verify @double
|
116
|
-
end
|
117
|
-
|
118
|
-
it "fails when called less than the specified number" do
|
119
|
-
@double.do_something
|
120
|
-
@double.do_something
|
121
|
-
expect { verify @double }.to raise_error
|
122
|
-
end
|
123
|
-
|
124
|
-
it "fails fast when called greater than the specified number" do
|
125
|
-
@double.do_something
|
126
|
-
@double.do_something
|
127
|
-
@double.do_something
|
128
|
-
expect { @double.do_something }.to raise_error
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|