rr 0.4.8 → 0.4.9
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/CHANGES +3 -0
- data/{README → README.rdoc} +14 -6
- data/Rakefile +2 -2
- data/lib/rr.rb +11 -3
- data/lib/rr/adapters/rr_methods.rb +12 -12
- data/lib/rr/adapters/rspec.rb +3 -3
- data/lib/rr/adapters/test_unit.rb +3 -3
- data/lib/rr/double.rb +12 -10
- data/lib/rr/double_creator.rb +48 -45
- data/lib/rr/double_definition.rb +17 -149
- data/lib/rr/double_definition_builder.rb +11 -11
- data/lib/rr/double_definition_creator.rb +156 -0
- data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
- data/lib/rr/double_injection.rb +6 -6
- data/lib/rr/double_matches.rb +40 -40
- data/lib/rr/errors/rr_error.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/space.rb +9 -30
- data/spec/high_level_spec.rb +140 -143
- data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
- data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
- data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
- data/spec/rr/double/double_injection_reset_spec.rb +1 -1
- data/spec/rr/double/double_injection_verify_spec.rb +5 -4
- data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
- data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
- data/spec/rr/double_definition_spec.rb +637 -642
- data/spec/rr/double_spec.rb +44 -43
- data/spec/rr/errors/rr_error_spec.rb +6 -6
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
- data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +372 -18
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
- data/spec/spec_helper.rb +14 -3
- data/spec/spec_suite.rb +2 -2
- metadata +47 -45
- data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
- data/spec/rr/space/space_create_spec.rb +0 -268
- data/spec/rr/space/space_helper.rb +0 -7
- data/spec/rr/space/space_register_spec.rb +0 -32
- data/spec/rr/space/space_reset_spec.rb +0 -131
- data/spec/rr/space/space_verify_spec.rb +0 -181
@@ -1,820 +1,815 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe DoubleDefinition, :shared => true do
|
5
|
-
before do
|
6
|
-
@space = Space.new
|
7
|
-
@object = Object.new
|
8
|
-
add_original_method
|
9
|
-
@double_injection = @space.double_injection(@object, :foobar)
|
10
|
-
@double = @space.double(@double_injection)
|
11
|
-
@definition = @double.definition
|
12
|
-
end
|
13
|
-
|
14
|
-
def add_original_method
|
15
|
-
def @object.foobar(a, b)
|
16
|
-
:original_return_value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
4
|
describe DoubleDefinition, " with returns block_callback_strategy", :shared => true do
|
22
5
|
before do
|
23
|
-
@definition.returns_block_callback_strategy
|
6
|
+
@definition.returns_block_callback_strategy
|
24
7
|
create_definition
|
25
8
|
end
|
26
9
|
end
|
27
10
|
|
28
11
|
describe DoubleDefinition, " with after_call block_callback_strategy", :shared => true do
|
29
12
|
before do
|
30
|
-
@definition.
|
31
|
-
@definition.after_call_block_callback_strategy
|
13
|
+
@definition.proxy
|
14
|
+
@definition.after_call_block_callback_strategy
|
32
15
|
create_definition
|
33
16
|
end
|
34
17
|
end
|
35
18
|
|
36
|
-
describe DoubleDefinition
|
37
|
-
it_should_behave_like "
|
19
|
+
describe DoubleDefinition do
|
20
|
+
it_should_behave_like "Swapped Space"
|
38
21
|
|
39
|
-
|
40
|
-
@
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@definition
|
45
|
-
@definition.should_not be_exact_match(2)
|
22
|
+
before do
|
23
|
+
@object = Object.new
|
24
|
+
add_original_method
|
25
|
+
@double_injection = Space.instance.double_injection(@object, :foobar)
|
26
|
+
@double = Double.new(@double_injection)
|
27
|
+
@definition = @double.definition
|
46
28
|
end
|
47
29
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
actual_args = args
|
52
|
-
:new_return_value
|
30
|
+
def add_original_method
|
31
|
+
def @object.foobar(a, b)
|
32
|
+
:original_return_value
|
53
33
|
end
|
54
|
-
@object.foobar(1, 2)
|
55
|
-
@return_value = @object.foobar(1, 2)
|
56
|
-
@args = actual_args
|
57
34
|
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe DoubleDefinition, "#with with returns block_callback_strategy" do
|
61
|
-
it_should_behave_like "RR::DoubleDefinition#with"
|
62
|
-
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
63
|
-
|
64
|
-
it "sets return value when block passed in" do
|
65
|
-
@return_value.should == :new_return_value
|
66
|
-
@args.should == [1, 2]
|
67
|
-
end
|
68
|
-
end
|
69
35
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@args.should == [:original_return_value]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe DoubleDefinition, "#with_any_args", :shared => true do
|
81
|
-
it_should_behave_like "RR::DoubleDefinition"
|
82
|
-
|
83
|
-
it "returns DoubleDefinition" do
|
84
|
-
@definition.with_no_args.should === @definition
|
85
|
-
end
|
86
|
-
|
87
|
-
it "sets an AnyArgumentExpectation" do
|
88
|
-
@definition.should_not be_exact_match(1)
|
89
|
-
@definition.should be_wildcard_match(1)
|
90
|
-
end
|
36
|
+
describe "#with" do
|
37
|
+
class << self
|
38
|
+
define_method "#with" do
|
39
|
+
it "returns DoubleDefinition" do
|
40
|
+
@definition.with(1).should === @definition
|
41
|
+
end
|
91
42
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
43
|
+
it "sets an ArgumentEqualityExpectation" do
|
44
|
+
@definition.should be_exact_match(1, 2)
|
45
|
+
@definition.should_not be_exact_match(2)
|
46
|
+
end
|
47
|
+
end
|
97
48
|
end
|
98
|
-
@return_value = @object.foobar(1, 2)
|
99
|
-
@args = actual_args
|
100
|
-
end
|
101
|
-
end
|
102
49
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
50
|
+
def create_definition
|
51
|
+
actual_args = nil
|
52
|
+
@definition.with(1, 2) do |*args|
|
53
|
+
actual_args = args
|
54
|
+
:new_return_value
|
55
|
+
end
|
56
|
+
@object.foobar(1, 2)
|
57
|
+
@return_value = @object.foobar(1, 2)
|
58
|
+
@args = actual_args
|
59
|
+
end
|
112
60
|
|
113
|
-
|
114
|
-
|
115
|
-
|
61
|
+
context "with returns block_callback_strategy" do
|
62
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
63
|
+
send "#with"
|
116
64
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
65
|
+
it "sets return value when block passed in" do
|
66
|
+
@return_value.should == :new_return_value
|
67
|
+
@args.should == [1, 2]
|
68
|
+
end
|
69
|
+
end
|
122
70
|
|
123
|
-
|
124
|
-
|
71
|
+
context "with after_call block_callback_strategy" do
|
72
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
73
|
+
send "#with"
|
125
74
|
|
126
|
-
|
127
|
-
|
75
|
+
it "sets return value when block passed in" do
|
76
|
+
@return_value.should == :new_return_value
|
77
|
+
@args.should == [:original_return_value]
|
78
|
+
end
|
79
|
+
end
|
128
80
|
end
|
129
81
|
|
130
|
-
|
131
|
-
|
132
|
-
|
82
|
+
describe "#with_any_args" do
|
83
|
+
class << self
|
84
|
+
define_method "#with_any_args" do
|
85
|
+
it "returns DoubleDefinition" do
|
86
|
+
@definition.with_no_args.should === @definition
|
87
|
+
end
|
133
88
|
|
134
|
-
|
135
|
-
|
136
|
-
|
89
|
+
it "sets an AnyArgumentExpectation" do
|
90
|
+
@definition.should_not be_exact_match(1)
|
91
|
+
@definition.should be_wildcard_match(1)
|
92
|
+
end
|
93
|
+
end
|
137
94
|
end
|
138
|
-
end
|
139
95
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
96
|
+
def create_definition
|
97
|
+
actual_args = nil
|
98
|
+
@definition.with_any_args do |*args|
|
99
|
+
actual_args = args
|
100
|
+
:new_return_value
|
101
|
+
end
|
102
|
+
@return_value = @object.foobar(1, 2)
|
103
|
+
@args = actual_args
|
145
104
|
end
|
146
|
-
@return_value = @object.foobar
|
147
|
-
@args = actual_args
|
148
|
-
end
|
149
|
-
end
|
150
105
|
|
151
|
-
|
152
|
-
|
153
|
-
|
106
|
+
describe "with returns block_callback_strategy" do
|
107
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
108
|
+
send "#with_any_args"
|
154
109
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
describe DoubleDefinition, "#with_no_args with after_call block_callback_strategy" do
|
162
|
-
it_should_behave_like "RR::DoubleDefinition#with_no_args"
|
163
|
-
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
164
|
-
|
165
|
-
it "sets return value when block passed in" do
|
166
|
-
@return_value.should == :new_return_value
|
167
|
-
@args.should == [:original_return_value]
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe DoubleDefinition, "#never" do
|
172
|
-
it_should_behave_like "RR::DoubleDefinition"
|
173
|
-
|
174
|
-
it "returns DoubleDefinition" do
|
175
|
-
@definition.never.should === @definition
|
176
|
-
end
|
110
|
+
it "sets return value when block passed in" do
|
111
|
+
@return_value.should == :new_return_value
|
112
|
+
@args.should == [1, 2]
|
113
|
+
end
|
114
|
+
end
|
177
115
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
proc {@object.foobar}.should raise_error(Errors::TimesCalledError)
|
182
|
-
end
|
116
|
+
describe "with after_call block_callback_strategy" do
|
117
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
118
|
+
send "#with_any_args"
|
183
119
|
|
184
|
-
|
185
|
-
|
186
|
-
|
120
|
+
it "sets return value when block passed in" do
|
121
|
+
@return_value.should == :new_return_value
|
122
|
+
@args.should == [:original_return_value]
|
123
|
+
end
|
124
|
+
end
|
187
125
|
end
|
188
|
-
end
|
189
126
|
|
190
|
-
|
191
|
-
|
127
|
+
describe "#with_no_args" do
|
128
|
+
class << self
|
129
|
+
define_method "#with_no_args" do
|
130
|
+
it "returns DoubleDefinition" do
|
131
|
+
@definition.with_no_args.should === @definition
|
132
|
+
end
|
192
133
|
|
193
|
-
|
194
|
-
|
195
|
-
|
134
|
+
it "sets an ArgumentEqualityExpectation with no arguments" do
|
135
|
+
@definition.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
196
139
|
|
197
|
-
|
198
|
-
|
199
|
-
|
140
|
+
def add_original_method
|
141
|
+
def @object.foobar()
|
142
|
+
:original_return_value
|
143
|
+
end
|
144
|
+
end
|
200
145
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
146
|
+
def create_definition
|
147
|
+
actual_args = nil
|
148
|
+
@definition.with_no_args do |*args|
|
149
|
+
actual_args = args
|
150
|
+
:new_return_value
|
151
|
+
end
|
152
|
+
@return_value = @object.foobar
|
153
|
+
@args = actual_args
|
206
154
|
end
|
207
|
-
@return_value = @object.foobar(1, 2)
|
208
|
-
@args = actual_args
|
209
|
-
end
|
210
|
-
end
|
211
155
|
|
212
|
-
|
213
|
-
|
214
|
-
|
156
|
+
context "with returns block_callback_strategy" do
|
157
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
158
|
+
send "#with_no_args"
|
215
159
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
160
|
+
it "sets return value when block passed in" do
|
161
|
+
@return_value.should == :new_return_value
|
162
|
+
@args.should == []
|
163
|
+
end
|
164
|
+
end
|
221
165
|
|
222
|
-
|
223
|
-
|
224
|
-
|
166
|
+
context "with after_call block_callback_strategy" do
|
167
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
168
|
+
send "#with_no_args"
|
225
169
|
|
226
|
-
|
227
|
-
|
228
|
-
|
170
|
+
it "sets return value when block passed in" do
|
171
|
+
@return_value.should == :new_return_value
|
172
|
+
@args.should == [:original_return_value]
|
173
|
+
end
|
174
|
+
end
|
229
175
|
end
|
230
|
-
end
|
231
176
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
@definition.twice.should === @definition
|
237
|
-
end
|
177
|
+
describe "#never" do
|
178
|
+
it "returns DoubleDefinition" do
|
179
|
+
@definition.never.should === @definition
|
180
|
+
end
|
238
181
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
182
|
+
it "sets up a Times Called Expectation with 0" do
|
183
|
+
@definition.with_any_args
|
184
|
+
@definition.never
|
185
|
+
lambda {@object.foobar}.should raise_error(Errors::TimesCalledError)
|
186
|
+
end
|
243
187
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
actual_args = args
|
248
|
-
:new_return_value
|
188
|
+
it "sets return value when block passed in" do
|
189
|
+
@definition.with_any_args.never
|
190
|
+
lambda {@object.foobar}.should raise_error(Errors::TimesCalledError)
|
249
191
|
end
|
250
|
-
@object.foobar(1, 2)
|
251
|
-
@return_value = @object.foobar(1, 2)
|
252
|
-
@args = actual_args
|
253
192
|
end
|
254
|
-
end
|
255
|
-
|
256
|
-
describe DoubleDefinition, "#twice with returns block_callback_strategy" do
|
257
|
-
it_should_behave_like "RR::DoubleDefinition#twice"
|
258
|
-
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
259
193
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
194
|
+
describe "#once" do
|
195
|
+
class << self
|
196
|
+
define_method "#once" do
|
197
|
+
it "returns DoubleDefinition" do
|
198
|
+
@definition.once.should === @definition
|
199
|
+
end
|
265
200
|
|
266
|
-
|
267
|
-
|
268
|
-
|
201
|
+
it "sets up a Times Called Expectation with 1" do
|
202
|
+
lambda {@object.foobar}.should raise_error(Errors::TimesCalledError)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
269
206
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
207
|
+
def create_definition
|
208
|
+
actual_args = nil
|
209
|
+
@definition.with_any_args.once do |*args|
|
210
|
+
actual_args = args
|
211
|
+
:new_return_value
|
212
|
+
end
|
213
|
+
@return_value = @object.foobar(1, 2)
|
214
|
+
@args = actual_args
|
215
|
+
end
|
275
216
|
|
276
|
-
|
277
|
-
|
217
|
+
context "with returns block_callback_strategy" do
|
218
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
219
|
+
send "#once"
|
278
220
|
|
279
|
-
|
280
|
-
|
281
|
-
|
221
|
+
it "sets return value when block passed in" do
|
222
|
+
@return_value.should == :new_return_value
|
223
|
+
@args.should == [1, 2]
|
224
|
+
end
|
225
|
+
end
|
282
226
|
|
283
|
-
|
284
|
-
|
285
|
-
|
227
|
+
context "with after_call block_callback_strategy" do
|
228
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
229
|
+
send "#once"
|
286
230
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
:new_return_value
|
231
|
+
it "sets return value when block passed in" do
|
232
|
+
@return_value.should == :new_return_value
|
233
|
+
@args.should == [:original_return_value]
|
234
|
+
end
|
292
235
|
end
|
293
|
-
@object.foobar(1, 2)
|
294
|
-
@return_value = @object.foobar(1, 2)
|
295
|
-
@args = actual_args
|
296
236
|
end
|
297
|
-
end
|
298
237
|
|
299
|
-
|
300
|
-
|
301
|
-
|
238
|
+
describe "#twice" do
|
239
|
+
class << self
|
240
|
+
define_method "#twice" do
|
241
|
+
it "returns DoubleDefinition" do
|
242
|
+
@definition.twice.should === @definition
|
243
|
+
end
|
302
244
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
describe DoubleDefinition, "#at_least with after_call block_callback_strategy" do
|
310
|
-
it_should_behave_like "RR::DoubleDefinition#at_least"
|
311
|
-
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
245
|
+
it "sets up a Times Called Expectation with 2" do
|
246
|
+
@definition.twice.with_any_args
|
247
|
+
lambda {@object.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
312
251
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
252
|
+
def create_definition
|
253
|
+
actual_args = nil
|
254
|
+
@definition.with_any_args.twice do |*args|
|
255
|
+
actual_args = args
|
256
|
+
:new_return_value
|
257
|
+
end
|
258
|
+
@object.foobar(1, 2)
|
259
|
+
@return_value = @object.foobar(1, 2)
|
260
|
+
@args = actual_args
|
261
|
+
end
|
318
262
|
|
319
|
-
|
320
|
-
|
263
|
+
context "with returns block_callback_strategy" do
|
264
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
265
|
+
send "#twice"
|
321
266
|
|
322
|
-
|
323
|
-
|
324
|
-
|
267
|
+
it "sets return value when block passed in" do
|
268
|
+
@return_value.should == :new_return_value
|
269
|
+
@args.should == [1, 2]
|
270
|
+
end
|
271
|
+
end
|
325
272
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
end.should raise_error(
|
330
|
-
Errors::TimesCalledError,
|
331
|
-
"foobar()\nCalled 3 times.\nExpected at most 2 times."
|
332
|
-
)
|
333
|
-
end
|
273
|
+
context "with after_call block_callback_strategy" do
|
274
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
275
|
+
send "#twice"
|
334
276
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
:new_return_value
|
277
|
+
it "sets return value when block passed in" do
|
278
|
+
@return_value.should == :new_return_value
|
279
|
+
@args.should == [:original_return_value]
|
280
|
+
end
|
340
281
|
end
|
341
|
-
@object.foobar(1, 2)
|
342
|
-
@return_value = @object.foobar(1, 2)
|
343
|
-
@args = actual_args
|
344
282
|
end
|
345
|
-
end
|
346
283
|
|
347
|
-
|
348
|
-
|
349
|
-
|
284
|
+
describe "#at_least" do
|
285
|
+
class << self
|
286
|
+
define_method "#at_least" do
|
287
|
+
it "returns DoubleDefinition" do
|
288
|
+
@definition.with_any_args.at_least(2).should === @definition
|
289
|
+
end
|
350
290
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
describe DoubleDefinition, "#at_most with after_call block_callback_strategy" do
|
358
|
-
it_should_behave_like "RR::DoubleDefinition#at_most"
|
359
|
-
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
291
|
+
it "sets up a Times Called Expectation with 1" do
|
292
|
+
@definition.times_matcher.should == TimesCalledMatchers::AtLeastMatcher.new(2)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
360
296
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
297
|
+
def create_definition
|
298
|
+
actual_args = nil
|
299
|
+
@definition.with_any_args.at_least(2) do |*args|
|
300
|
+
actual_args = args
|
301
|
+
:new_return_value
|
302
|
+
end
|
303
|
+
@object.foobar(1, 2)
|
304
|
+
@return_value = @object.foobar(1, 2)
|
305
|
+
@args = actual_args
|
306
|
+
end
|
366
307
|
|
367
|
-
|
368
|
-
|
308
|
+
context "with returns block_callback_strategy" do
|
309
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
310
|
+
send "#at_least"
|
369
311
|
|
370
|
-
|
371
|
-
|
372
|
-
|
312
|
+
it "sets return value when block passed in" do
|
313
|
+
@return_value.should == :new_return_value
|
314
|
+
@args.should == [1, 2]
|
315
|
+
end
|
316
|
+
end
|
373
317
|
|
374
|
-
|
375
|
-
|
376
|
-
|
318
|
+
context "with after_call block_callback_strategy" do
|
319
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
320
|
+
send "#at_least"
|
377
321
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
:new_return_value
|
322
|
+
it "sets return value when block passed in" do
|
323
|
+
@return_value.should == :new_return_value
|
324
|
+
@args.should == [:original_return_value]
|
325
|
+
end
|
383
326
|
end
|
384
|
-
@object.foobar(1, 2)
|
385
|
-
@object.foobar(1, 2)
|
386
|
-
@return_value = @object.foobar(1, 2)
|
387
|
-
@args = actual_args
|
388
327
|
end
|
389
|
-
end
|
390
328
|
|
391
|
-
|
392
|
-
|
393
|
-
|
329
|
+
describe "#at_most" do
|
330
|
+
class << self
|
331
|
+
define_method "#at_most" do
|
332
|
+
it "returns DoubleDefinition" do
|
333
|
+
@definition.with_any_args.at_most(2).should === @definition
|
334
|
+
end
|
335
|
+
|
336
|
+
it "sets up a Times Called Expectation with 1" do
|
337
|
+
lambda do
|
338
|
+
@object.foobar
|
339
|
+
end.should raise_error(
|
340
|
+
Errors::TimesCalledError,
|
341
|
+
"foobar()\nCalled 3 times.\nExpected at most 2 times."
|
342
|
+
)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
394
346
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
347
|
+
def create_definition
|
348
|
+
actual_args = nil
|
349
|
+
@definition.with_any_args.at_most(2) do |*args|
|
350
|
+
actual_args = args
|
351
|
+
:new_return_value
|
352
|
+
end
|
353
|
+
@object.foobar(1, 2)
|
354
|
+
@return_value = @object.foobar(1, 2)
|
355
|
+
@args = actual_args
|
356
|
+
end
|
357
|
+
|
358
|
+
context "with returns block_callback_strategy" do
|
359
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
360
|
+
send "#at_most"
|
361
|
+
|
362
|
+
it "sets return value when block passed in" do
|
363
|
+
@return_value.should == :new_return_value
|
364
|
+
@args.should == [1, 2]
|
365
|
+
end
|
366
|
+
end
|
400
367
|
|
401
|
-
|
402
|
-
|
403
|
-
|
368
|
+
context "with after_call block_callback_strategy" do
|
369
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
370
|
+
send "#at_most"
|
404
371
|
|
405
|
-
|
406
|
-
|
407
|
-
|
372
|
+
it "sets return value when block passed in" do
|
373
|
+
@return_value.should == :new_return_value
|
374
|
+
@args.should == [:original_return_value]
|
375
|
+
end
|
376
|
+
end
|
408
377
|
end
|
409
|
-
end
|
410
|
-
|
411
|
-
describe DoubleDefinition, "#any_number_of_times", :shared => true do
|
412
|
-
it_should_behave_like "RR::DoubleDefinition"
|
413
378
|
|
414
|
-
|
415
|
-
|
416
|
-
|
379
|
+
describe "#times" do
|
380
|
+
class << self
|
381
|
+
define_method "#times" do
|
382
|
+
it "returns DoubleDefinition" do
|
383
|
+
@definition.times(3).should === @definition
|
384
|
+
end
|
417
385
|
|
418
|
-
|
419
|
-
|
420
|
-
|
386
|
+
it "sets up a Times Called Expectation with passed in times" do
|
387
|
+
lambda {@object.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
421
391
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
392
|
+
def create_definition
|
393
|
+
actual_args = nil
|
394
|
+
@definition.with(1, 2).times(3) do |*args|
|
395
|
+
actual_args = args
|
396
|
+
:new_return_value
|
397
|
+
end
|
398
|
+
@object.foobar(1, 2)
|
399
|
+
@object.foobar(1, 2)
|
400
|
+
@return_value = @object.foobar(1, 2)
|
401
|
+
@args = actual_args
|
427
402
|
end
|
428
|
-
@object.foobar(1, 2)
|
429
|
-
@return_value = @object.foobar(1, 2)
|
430
|
-
@args = actual_args
|
431
|
-
end
|
432
|
-
end
|
433
403
|
|
434
|
-
|
435
|
-
|
436
|
-
|
404
|
+
context "with returns block_callback_strategy" do
|
405
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
406
|
+
send "#times"
|
437
407
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
408
|
+
it "sets return value when block passed in" do
|
409
|
+
@return_value.should == :new_return_value
|
410
|
+
@args.should == [1, 2]
|
411
|
+
end
|
412
|
+
end
|
443
413
|
|
444
|
-
|
445
|
-
|
446
|
-
|
414
|
+
context "with after_call block_callback_strategy" do
|
415
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
416
|
+
send "#times"
|
447
417
|
|
448
|
-
|
449
|
-
|
450
|
-
|
418
|
+
it "sets return value when block passed in" do
|
419
|
+
@return_value.should == :new_return_value
|
420
|
+
@args.should == [:original_return_value]
|
421
|
+
end
|
422
|
+
end
|
451
423
|
end
|
452
|
-
end
|
453
424
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
end
|
425
|
+
describe "#any_number_of_times" do
|
426
|
+
class << self
|
427
|
+
define_method "#any_number_of_times" do
|
428
|
+
it "returns DoubleDefinition" do
|
429
|
+
@definition.any_number_of_times.should === @definition
|
430
|
+
end
|
461
431
|
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
432
|
+
it "sets up a Times Called Expectation with AnyTimes matcher" do
|
433
|
+
@definition.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|
466
437
|
|
467
|
-
|
468
|
-
|
469
|
-
|
438
|
+
def create_definition
|
439
|
+
actual_args = nil
|
440
|
+
@definition.with(1, 2).any_number_of_times do |*args|
|
441
|
+
actual_args = args
|
442
|
+
:new_return_value
|
443
|
+
end
|
444
|
+
@object.foobar(1, 2)
|
445
|
+
@return_value = @object.foobar(1, 2)
|
446
|
+
@args = actual_args
|
447
|
+
end
|
470
448
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
@definition.ordered
|
475
|
-
end.should raise_error(
|
476
|
-
Errors::DoubleDefinitionError,
|
477
|
-
"Double Definitions must have a dedicated Double to be ordered. " <<
|
478
|
-
"For example, using instance_of does not allow ordered to be used. " <<
|
479
|
-
"proxy the class's #new method instead."
|
480
|
-
)
|
481
|
-
end
|
449
|
+
context "with returns block_callback_strategy" do
|
450
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
451
|
+
send "#any_number_of_times"
|
482
452
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
:new_return_value
|
453
|
+
it "sets return value when block passed in" do
|
454
|
+
@return_value.should == :new_return_value
|
455
|
+
@args.should == [1, 2]
|
456
|
+
end
|
488
457
|
end
|
489
|
-
@return_value = @object.foobar(1, 2)
|
490
|
-
@args = actual_args
|
491
|
-
end
|
492
|
-
end
|
493
458
|
|
494
|
-
|
495
|
-
|
496
|
-
|
459
|
+
context "with after_call block_callback_strategy" do
|
460
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
461
|
+
send "#any_number_of_times"
|
497
462
|
|
498
|
-
|
499
|
-
|
500
|
-
|
463
|
+
it "sets return value when block passed in" do
|
464
|
+
@return_value.should == :new_return_value
|
465
|
+
@args.should == [:original_return_value]
|
466
|
+
end
|
467
|
+
end
|
501
468
|
end
|
502
|
-
end
|
503
469
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
470
|
+
describe "#ordered" do
|
471
|
+
class << self
|
472
|
+
define_method "#ordered" do
|
473
|
+
it "adds itself to the ordered doubles list" do
|
474
|
+
@definition.ordered
|
475
|
+
Space.instance.ordered_doubles.should include(@double)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "does not double_injection add itself" do
|
479
|
+
@definition.ordered
|
480
|
+
Space.instance.ordered_doubles.should == [@double]
|
481
|
+
end
|
482
|
+
|
483
|
+
it "sets ordered? to true" do
|
484
|
+
@definition.should be_ordered
|
485
|
+
end
|
486
|
+
|
487
|
+
it "raises error when there is no Double" do
|
488
|
+
@definition.double = nil
|
489
|
+
lambda do
|
490
|
+
@definition.ordered
|
491
|
+
end.should raise_error(
|
492
|
+
Errors::DoubleDefinitionError,
|
493
|
+
"Double Definitions must have a dedicated Double to be ordered. " <<
|
494
|
+
"For example, using instance_of does not allow ordered to be used. " <<
|
495
|
+
"proxy the class's #new method instead."
|
496
|
+
)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
513
500
|
|
514
|
-
|
515
|
-
|
501
|
+
def create_definition
|
502
|
+
actual_args = nil
|
503
|
+
@definition.with(1, 2).once.ordered do |*args|
|
504
|
+
actual_args = args
|
505
|
+
:new_return_value
|
506
|
+
end
|
507
|
+
@return_value = @object.foobar(1, 2)
|
508
|
+
@args = actual_args
|
509
|
+
end
|
516
510
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
end
|
511
|
+
context "with returns block_callback_strategy" do
|
512
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
513
|
+
send "#ordered"
|
521
514
|
|
522
|
-
|
523
|
-
|
515
|
+
it "sets return value when block passed in" do
|
516
|
+
@return_value.should == :new_return_value
|
517
|
+
@args.should == [1, 2]
|
518
|
+
end
|
519
|
+
end
|
524
520
|
|
525
|
-
|
526
|
-
|
527
|
-
|
521
|
+
context "with after_call block_callback_strategy" do
|
522
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
523
|
+
send "#ordered"
|
528
524
|
|
529
|
-
|
530
|
-
|
525
|
+
it "sets return value when block passed in" do
|
526
|
+
@return_value.should == :new_return_value
|
527
|
+
@args.should == [:original_return_value]
|
528
|
+
end
|
529
|
+
end
|
531
530
|
end
|
532
531
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
actual_args = args
|
537
|
-
:new_return_value
|
538
|
-
end
|
539
|
-
passed_in_block_arg = nil
|
540
|
-
@return_value = @object.foobar(1, 2) do |arg|
|
541
|
-
passed_in_block_arg = arg
|
532
|
+
describe "#ordered?" do
|
533
|
+
it "defaults to false" do
|
534
|
+
@definition.should_not be_ordered
|
542
535
|
end
|
543
|
-
@passed_in_block_arg = passed_in_block_arg
|
544
|
-
|
545
|
-
@args = actual_args
|
546
536
|
end
|
547
|
-
end
|
548
537
|
|
549
|
-
|
550
|
-
|
551
|
-
|
538
|
+
describe "#yields" do
|
539
|
+
class << self
|
540
|
+
define_method "#yields" do
|
541
|
+
it "returns DoubleDefinition" do
|
542
|
+
@definition.yields(:baz).should === @definition
|
543
|
+
end
|
552
544
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
end
|
559
|
-
end
|
560
|
-
|
561
|
-
describe DoubleDefinition, "#yields with after_call block_callback_strategy" do
|
562
|
-
it_should_behave_like "RR::DoubleDefinition#yields"
|
563
|
-
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
545
|
+
it "yields the passed in argument to the call block when there is a no returns value set" do
|
546
|
+
@passed_in_block_arg.should == :baz
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|
564
550
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
551
|
+
def create_definition
|
552
|
+
actual_args = nil
|
553
|
+
@definition.with(1, 2).once.yields(:baz) do |*args|
|
554
|
+
actual_args = args
|
555
|
+
:new_return_value
|
556
|
+
end
|
557
|
+
passed_in_block_arg = nil
|
558
|
+
@return_value = @object.foobar(1, 2) do |arg|
|
559
|
+
passed_in_block_arg = arg
|
560
|
+
end
|
561
|
+
@passed_in_block_arg = passed_in_block_arg
|
570
562
|
|
571
|
-
|
572
|
-
|
563
|
+
@args = actual_args
|
564
|
+
end
|
573
565
|
|
574
|
-
|
575
|
-
|
576
|
-
|
566
|
+
context "with returns block_callback_strategy" do
|
567
|
+
it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
|
568
|
+
send "#yields"
|
577
569
|
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
570
|
+
it "sets return value when block passed in" do
|
571
|
+
@return_value.should == :new_return_value
|
572
|
+
@args.length.should == 3
|
573
|
+
@args[0..1].should == [1, 2]
|
574
|
+
@args[2].should be_instance_of(Proc)
|
575
|
+
end
|
583
576
|
end
|
584
577
|
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
end
|
578
|
+
context "with after_call block_callback_strategy" do
|
579
|
+
it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
|
580
|
+
send "#yields"
|
589
581
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
582
|
+
it "sets return value when block passed in" do
|
583
|
+
@return_value.should == :new_return_value
|
584
|
+
@args.should == [:original_return_value]
|
585
|
+
end
|
594
586
|
end
|
595
|
-
|
596
|
-
actual_value = @object.foobar
|
597
|
-
actual_value.should == :after_call_value
|
598
587
|
end
|
599
588
|
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
mock(value).inner_method(1) {:baz}
|
604
|
-
value
|
589
|
+
describe "#after_call" do
|
590
|
+
it "returns DoubleDefinition" do
|
591
|
+
@definition.after_call {}.should === @definition
|
605
592
|
end
|
606
593
|
|
607
|
-
|
608
|
-
|
594
|
+
it "sends return value of Double implementation to after_call" do
|
595
|
+
return_value = {}
|
596
|
+
@definition.with_any_args.returns(return_value).after_call do |value|
|
597
|
+
value[:foo] = :bar
|
598
|
+
value
|
599
|
+
end
|
609
600
|
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
end
|
614
|
-
end
|
615
|
-
end
|
601
|
+
actual_value = @object.foobar
|
602
|
+
actual_value.should === return_value
|
603
|
+
actual_value.should == {:foo => :bar}
|
604
|
+
end
|
616
605
|
|
617
|
-
|
618
|
-
|
606
|
+
it "receives the return value in the after_call callback" do
|
607
|
+
return_value = :returns_value
|
608
|
+
@definition.with_any_args.returns(return_value).after_call do |value|
|
609
|
+
:after_call_value
|
610
|
+
end
|
619
611
|
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
end
|
612
|
+
actual_value = @object.foobar
|
613
|
+
actual_value.should == :after_call_value
|
614
|
+
end
|
624
615
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
616
|
+
it "allows after_call to mock the return value" do
|
617
|
+
return_value = Object.new
|
618
|
+
@definition.with_any_args.returns(return_value).after_call do |value|
|
619
|
+
mock(value).inner_method(1) {:baz}
|
620
|
+
value
|
621
|
+
end
|
629
622
|
|
630
|
-
|
631
|
-
|
632
|
-
@object.foobar.should == :baz
|
633
|
-
end
|
623
|
+
@object.foobar.inner_method(1).should == :baz
|
624
|
+
end
|
634
625
|
|
635
|
-
|
636
|
-
|
637
|
-
|
626
|
+
it "raises an error when not passed a block" do
|
627
|
+
lambda do
|
628
|
+
@definition.after_call
|
629
|
+
end.should raise_error(ArgumentError, "after_call expects a block")
|
630
|
+
end
|
638
631
|
end
|
639
632
|
|
640
|
-
|
641
|
-
|
642
|
-
@definition.returns
|
643
|
-
|
644
|
-
|
645
|
-
end
|
633
|
+
describe "#returns" do
|
634
|
+
it "returns DoubleDefinition" do
|
635
|
+
@definition.returns {:baz}.should === @definition
|
636
|
+
@definition.returns(:baz).should === @definition
|
637
|
+
end
|
646
638
|
|
647
|
-
|
648
|
-
|
639
|
+
it "sets the value of the method when passed a block" do
|
640
|
+
@definition.with_any_args.returns {:baz}
|
641
|
+
@object.foobar.should == :baz
|
642
|
+
end
|
649
643
|
|
650
|
-
|
651
|
-
|
652
|
-
|
644
|
+
it "sets the value of the method when passed an argument" do
|
645
|
+
@definition.returns(:baz).with_no_args
|
646
|
+
@object.foobar.should == :baz
|
647
|
+
end
|
653
648
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
649
|
+
it "returns false when passed false" do
|
650
|
+
@definition.returns(false).with_any_args
|
651
|
+
@object.foobar.should == false
|
652
|
+
end
|
658
653
|
|
659
|
-
|
660
|
-
|
661
|
-
|
654
|
+
it "raises an error when both argument and block is passed in" do
|
655
|
+
lambda do
|
656
|
+
@definition.returns(:baz) {:another}
|
657
|
+
end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
|
662
658
|
end
|
663
|
-
@definition.implemented_by(@object.method(:foobar))
|
664
|
-
@object.foobar(1, 2).should == [2, 1]
|
665
659
|
end
|
666
|
-
end
|
667
660
|
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
@definition.implemented_by_original_method.should === @definition
|
673
|
-
end
|
661
|
+
describe "#implemented_by" do
|
662
|
+
it "returns the DoubleDefinition" do
|
663
|
+
@definition.implemented_by(lambda{:baz}).should === @definition
|
664
|
+
end
|
674
665
|
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
666
|
+
it "sets the implementation to the passed in lambda" do
|
667
|
+
@definition.implemented_by(lambda{:baz}).with_no_args
|
668
|
+
@object.foobar.should == :baz
|
669
|
+
end
|
679
670
|
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
"method_missing for #{method_name}(#{args.inspect})"
|
671
|
+
it "sets the implementation to the passed in method" do
|
672
|
+
def @object.foobar(a, b)
|
673
|
+
[b, a]
|
684
674
|
end
|
675
|
+
@definition.implemented_by(@object.method(:foobar))
|
676
|
+
@object.foobar(1, 2).should == [2, 1]
|
685
677
|
end
|
686
|
-
double_injection = @space.double_injection(@object, :does_not_exist)
|
687
|
-
double = @space.double(double_injection)
|
688
|
-
double.with_any_args
|
689
|
-
double.implemented_by_original_method
|
690
|
-
|
691
|
-
return_value = @object.does_not_exist(1, 2)
|
692
|
-
return_value.should == "method_missing for does_not_exist([1, 2])"
|
693
|
-
end
|
694
|
-
end
|
695
|
-
|
696
|
-
describe DoubleDefinition, "#exact_match?" do
|
697
|
-
it_should_behave_like "RR::DoubleDefinition"
|
698
|
-
|
699
|
-
it "returns false when no expectation set" do
|
700
|
-
@definition.should_not be_exact_match()
|
701
|
-
@definition.should_not be_exact_match(nil)
|
702
|
-
@definition.should_not be_exact_match(Object.new)
|
703
|
-
@definition.should_not be_exact_match(1, 2, 3)
|
704
678
|
end
|
705
679
|
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
@definition.should_not be_exact_match()
|
711
|
-
@definition.should_not be_exact_match("does not match")
|
712
|
-
end
|
680
|
+
describe "#proxy" do
|
681
|
+
it "returns the DoubleDefinition object" do
|
682
|
+
@definition.proxy.should === @definition
|
683
|
+
end
|
713
684
|
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
end
|
685
|
+
it "sets the implementation to the original method" do
|
686
|
+
@definition.proxy.with_any_args
|
687
|
+
@object.foobar(1, 2).should == :original_return_value
|
688
|
+
end
|
719
689
|
|
720
|
-
|
721
|
-
|
690
|
+
it "calls method_missing when original_method does not exist" do
|
691
|
+
class << @object
|
692
|
+
def method_missing(method_name, *args, &block)
|
693
|
+
"method_missing for #{method_name}(#{args.inspect})"
|
694
|
+
end
|
695
|
+
end
|
696
|
+
double_injection = Space.instance.double_injection(@object, :does_not_exist)
|
697
|
+
double = Double.new(double_injection)
|
698
|
+
double.with_any_args
|
699
|
+
double.proxy
|
722
700
|
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
@definition.should_not be_wildcard_match(Object.new)
|
727
|
-
@definition.should_not be_wildcard_match(1, 2, 3)
|
701
|
+
return_value = @object.does_not_exist(1, 2)
|
702
|
+
return_value.should == "method_missing for does_not_exist([1, 2])"
|
703
|
+
end
|
728
704
|
end
|
729
705
|
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
end
|
706
|
+
describe "#exact_match?" do
|
707
|
+
it "returns false when no expectation set" do
|
708
|
+
@definition.should_not be_exact_match()
|
709
|
+
@definition.should_not be_exact_match(nil)
|
710
|
+
@definition.should_not be_exact_match(Object.new)
|
711
|
+
@definition.should_not be_exact_match(1, 2, 3)
|
712
|
+
end
|
738
713
|
|
739
|
-
|
740
|
-
|
714
|
+
it "returns false when arguments are not an exact match" do
|
715
|
+
@definition.with(1, 2, 3)
|
716
|
+
@definition.should_not be_exact_match(1, 2)
|
717
|
+
@definition.should_not be_exact_match(1)
|
718
|
+
@definition.should_not be_exact_match()
|
719
|
+
@definition.should_not be_exact_match("does not match")
|
720
|
+
end
|
741
721
|
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
@definition.should be_wildcard_match("does not match")
|
722
|
+
it "returns true when arguments are an exact match" do
|
723
|
+
@definition.with(1, 2, 3)
|
724
|
+
@definition.should be_exact_match(1, 2, 3)
|
725
|
+
end
|
747
726
|
end
|
748
|
-
end
|
749
727
|
|
750
|
-
|
751
|
-
|
728
|
+
describe "#wildcard_match?" do
|
729
|
+
it "returns false when no expectation set" do
|
730
|
+
@definition.should_not be_wildcard_match()
|
731
|
+
@definition.should_not be_wildcard_match(nil)
|
732
|
+
@definition.should_not be_wildcard_match(Object.new)
|
733
|
+
@definition.should_not be_wildcard_match(1, 2, 3)
|
734
|
+
end
|
752
735
|
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
736
|
+
it "returns true when arguments are an exact match" do
|
737
|
+
@definition.with(1, 2, 3)
|
738
|
+
@definition.should be_wildcard_match(1, 2, 3)
|
739
|
+
@definition.should_not be_wildcard_match(1, 2)
|
740
|
+
@definition.should_not be_wildcard_match(1)
|
741
|
+
@definition.should_not be_wildcard_match()
|
742
|
+
@definition.should_not be_wildcard_match("does not match")
|
743
|
+
end
|
758
744
|
|
759
|
-
|
760
|
-
|
761
|
-
@definition.times_matcher.should_not be_terminal
|
762
|
-
@definition.should_not be_terminal
|
763
|
-
end
|
745
|
+
it "returns true when with_any_args" do
|
746
|
+
@definition.with_any_args
|
764
747
|
|
765
|
-
|
766
|
-
|
767
|
-
|
748
|
+
@definition.should be_wildcard_match(1, 2, 3)
|
749
|
+
@definition.should be_wildcard_match(1, 2)
|
750
|
+
@definition.should be_wildcard_match(1)
|
751
|
+
@definition.should be_wildcard_match()
|
752
|
+
@definition.should be_wildcard_match("does not match")
|
753
|
+
end
|
768
754
|
end
|
769
|
-
end
|
770
755
|
|
771
|
-
|
772
|
-
|
756
|
+
describe "#terminal?" do
|
757
|
+
it "returns true when times_matcher's terminal? is true" do
|
758
|
+
@definition.once
|
759
|
+
@definition.times_matcher.should be_terminal
|
760
|
+
@definition.should be_terminal
|
761
|
+
end
|
773
762
|
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
763
|
+
it "returns false when times_matcher's terminal? is false" do
|
764
|
+
@definition.any_number_of_times
|
765
|
+
@definition.times_matcher.should_not be_terminal
|
766
|
+
@definition.should_not be_terminal
|
767
|
+
end
|
778
768
|
|
779
|
-
|
780
|
-
|
781
|
-
|
769
|
+
it "returns false when there is not times_matcher" do
|
770
|
+
@definition.times_matcher.should be_nil
|
771
|
+
@definition.should_not be_terminal
|
772
|
+
end
|
782
773
|
end
|
783
|
-
end
|
784
774
|
|
785
|
-
|
786
|
-
|
775
|
+
describe "#expected_arguments" do
|
776
|
+
it "returns argument expectation's expected_arguments when there is a argument expectation" do
|
777
|
+
@definition.with(1, 2)
|
778
|
+
@definition.expected_arguments.should == [1, 2]
|
779
|
+
end
|
787
780
|
|
788
|
-
|
789
|
-
|
781
|
+
it "returns an empty array when there is no argument expectation" do
|
782
|
+
@definition.argument_expectation.should be_nil
|
783
|
+
@definition.expected_arguments.should == []
|
784
|
+
end
|
790
785
|
end
|
791
|
-
end
|
792
|
-
|
793
|
-
describe DoubleDefinition, "#returns_block_callback_strategy!" do
|
794
|
-
it_should_behave_like "RR::DoubleDefinition"
|
795
786
|
|
796
|
-
|
797
|
-
|
798
|
-
|
787
|
+
describe "#block_callback_strategy" do
|
788
|
+
it "defaults to :returns" do
|
789
|
+
@definition.block_callback_strategy.should == :returns
|
790
|
+
end
|
799
791
|
end
|
800
|
-
end
|
801
792
|
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
@definition.block_callback_strategy.should == :after_call
|
793
|
+
describe "#returns_block_callback_strategy!" do
|
794
|
+
it "sets the block_callback_strategy to :returns" do
|
795
|
+
@definition.returns_block_callback_strategy
|
796
|
+
@definition.block_callback_strategy.should == :returns
|
797
|
+
end
|
808
798
|
end
|
809
|
-
end
|
810
799
|
|
811
|
-
|
812
|
-
|
800
|
+
describe "#after_call_block_callback_strategy!" do
|
801
|
+
it "sets the block_callback_strategy to :after_call" do
|
802
|
+
@definition.after_call_block_callback_strategy
|
803
|
+
@definition.block_callback_strategy.should == :after_call
|
804
|
+
end
|
805
|
+
end
|
813
806
|
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
807
|
+
describe "#verbose" do
|
808
|
+
it "sets the verbose? to true" do
|
809
|
+
@definition.should_not be_verbose
|
810
|
+
@definition.verbose
|
811
|
+
@definition.should be_verbose
|
812
|
+
end
|
818
813
|
end
|
819
814
|
end
|
820
815
|
end
|