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.
Files changed (52) hide show
  1. data/CHANGES +3 -0
  2. data/{README → README.rdoc} +14 -6
  3. data/Rakefile +2 -2
  4. data/lib/rr.rb +11 -3
  5. data/lib/rr/adapters/rr_methods.rb +12 -12
  6. data/lib/rr/adapters/rspec.rb +3 -3
  7. data/lib/rr/adapters/test_unit.rb +3 -3
  8. data/lib/rr/double.rb +12 -10
  9. data/lib/rr/double_creator.rb +48 -45
  10. data/lib/rr/double_definition.rb +17 -149
  11. data/lib/rr/double_definition_builder.rb +11 -11
  12. data/lib/rr/double_definition_creator.rb +156 -0
  13. data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
  14. data/lib/rr/double_injection.rb +6 -6
  15. data/lib/rr/double_matches.rb +40 -40
  16. data/lib/rr/errors/rr_error.rb +1 -1
  17. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  18. data/lib/rr/space.rb +9 -30
  19. data/spec/high_level_spec.rb +140 -143
  20. data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
  21. data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
  22. data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
  23. data/spec/rr/double/double_injection_reset_spec.rb +1 -1
  24. data/spec/rr/double/double_injection_verify_spec.rb +5 -4
  25. data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
  26. data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
  27. data/spec/rr/double_definition_spec.rb +637 -642
  28. data/spec/rr/double_spec.rb +44 -43
  29. data/spec/rr/errors/rr_error_spec.rb +6 -6
  30. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
  31. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
  32. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
  34. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
  35. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
  36. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
  37. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
  38. data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
  39. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
  40. data/spec/rr/space/space_spec.rb +372 -18
  41. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
  42. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
  43. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
  44. data/spec/spec_helper.rb +14 -3
  45. data/spec/spec_suite.rb +2 -2
  46. metadata +47 -45
  47. data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
  48. data/spec/rr/space/space_create_spec.rb +0 -268
  49. data/spec/rr/space/space_helper.rb +0 -7
  50. data/spec/rr/space/space_register_spec.rb +0 -32
  51. data/spec/rr/space/space_reset_spec.rb +0 -131
  52. 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.implemented_by_original_method
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, "#with", :shared => true do
37
- it_should_behave_like "RR::DoubleDefinition"
19
+ describe DoubleDefinition do
20
+ it_should_behave_like "Swapped Space"
38
21
 
39
- it "returns DoubleDefinition" do
40
- @definition.with(1).should === @definition
41
- end
42
-
43
- it "sets an ArgumentEqualityExpectation" do
44
- @definition.should be_exact_match(1, 2)
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 create_definition
49
- actual_args = nil
50
- @definition.with(1, 2) do |*args|
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
- describe DoubleDefinition, "#with with after_call block_callback_strategy" do
71
- it_should_behave_like "RR::DoubleDefinition#with"
72
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
73
-
74
- it "sets return value when block passed in" do
75
- @return_value.should == :new_return_value
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
- def create_definition
93
- actual_args = nil
94
- @definition.with_any_args do |*args|
95
- actual_args = args
96
- :new_return_value
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
- describe DoubleDefinition, "#with_any_args with returns block_callback_strategy" do
104
- it_should_behave_like "RR::DoubleDefinition#with_any_args"
105
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
106
-
107
- it "sets return value when block passed in" do
108
- @return_value.should == :new_return_value
109
- @args.should == [1, 2]
110
- end
111
- end
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
- describe DoubleDefinition, "#with_any_args with after_call block_callback_strategy" do
114
- it_should_behave_like "RR::DoubleDefinition#with_any_args"
115
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
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
- it "sets return value when block passed in" do
118
- @return_value.should == :new_return_value
119
- @args.should == [:original_return_value]
120
- end
121
- end
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
- describe DoubleDefinition, "#with_no_args", :shared => true do
124
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
127
- @definition.with_no_args.should === @definition
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
- it "sets an ArgumentEqualityExpectation with no arguments" do
131
- @definition.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
132
- end
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
- def add_original_method
135
- def @object.foobar()
136
- :original_return_value
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
- def create_definition
141
- actual_args = nil
142
- @definition.with_no_args do |*args|
143
- actual_args = args
144
- :new_return_value
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
- describe DoubleDefinition, "#with_no_args with returns block_callback_strategy" do
152
- it_should_behave_like "RR::DoubleDefinition#with_no_args"
153
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
156
- @return_value.should == :new_return_value
157
- @args.should == []
158
- end
159
- end
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
- it "sets up a Times Called Expectation with 0" do
179
- @definition.with_any_args
180
- @definition.never
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
- it "sets return value when block passed in" do
185
- @definition.with_any_args.never
186
- proc {@object.foobar}.should raise_error(Errors::TimesCalledError)
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
- describe DoubleDefinition, "#once", :shared => true do
191
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
194
- @definition.once.should === @definition
195
- end
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
- it "sets up a Times Called Expectation with 1" do
198
- proc {@object.foobar}.should raise_error(Errors::TimesCalledError)
199
- end
140
+ def add_original_method
141
+ def @object.foobar()
142
+ :original_return_value
143
+ end
144
+ end
200
145
 
201
- def create_definition
202
- actual_args = nil
203
- @definition.with_any_args.once do |*args|
204
- actual_args = args
205
- :new_return_value
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
- describe DoubleDefinition, "#once with returns block_callback_strategy" do
213
- it_should_behave_like "RR::DoubleDefinition#once"
214
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
217
- @return_value.should == :new_return_value
218
- @args.should == [1, 2]
219
- end
220
- end
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
- describe DoubleDefinition, "#once with after_call block_callback_strategy" do
223
- it_should_behave_like "RR::DoubleDefinition#once"
224
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
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
- it "sets return value when block passed in" do
227
- @return_value.should == :new_return_value
228
- @args.should == [:original_return_value]
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
- describe DoubleDefinition, "#twice", :shared => true do
233
- it_should_behave_like "RR::DoubleDefinition"
234
-
235
- it "returns DoubleDefinition" do
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
- it "sets up a Times Called Expectation with 2" do
240
- @definition.twice.with_any_args
241
- proc {@object.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
242
- end
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
- def create_definition
245
- actual_args = nil
246
- @definition.with_any_args.twice do |*args|
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
- it "sets return value when block passed in" do
261
- @return_value.should == :new_return_value
262
- @args.should == [1, 2]
263
- end
264
- end
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
- describe DoubleDefinition, "#twice with after_call block_callback_strategy" do
267
- it_should_behave_like "RR::DoubleDefinition#twice"
268
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
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
- it "sets return value when block passed in" do
271
- @return_value.should == :new_return_value
272
- @args.should == [:original_return_value]
273
- end
274
- end
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
- describe DoubleDefinition, "#at_least", :shared => true do
277
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
280
- @definition.with_any_args.at_least(2).should === @definition
281
- end
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
- it "sets up a Times Called Expectation with 1" do
284
- @definition.times_matcher.should == TimesCalledMatchers::AtLeastMatcher.new(2)
285
- end
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
- def create_definition
288
- actual_args = nil
289
- @definition.with_any_args.at_least(2) do |*args|
290
- actual_args = args
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
- describe DoubleDefinition, "#at_least with returns block_callback_strategy" do
300
- it_should_behave_like "RR::DoubleDefinition#at_least"
301
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
304
- @return_value.should == :new_return_value
305
- @args.should == [1, 2]
306
- end
307
- end
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
- it "sets return value when block passed in" do
314
- @return_value.should == :new_return_value
315
- @args.should == [:original_return_value]
316
- end
317
- end
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
- describe DoubleDefinition, "#at_most", :shared => true do
320
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
323
- @definition.with_any_args.at_most(2).should === @definition
324
- end
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
- it "sets up a Times Called Expectation with 1" do
327
- proc do
328
- @object.foobar
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
- def create_definition
336
- actual_args = nil
337
- @definition.with_any_args.at_most(2) do |*args|
338
- actual_args = args
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
- describe DoubleDefinition, "#at_most with returns block_callback_strategy" do
348
- it_should_behave_like "RR::DoubleDefinition#at_most"
349
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
352
- @return_value.should == :new_return_value
353
- @args.should == [1, 2]
354
- end
355
- end
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
- it "sets return value when block passed in" do
362
- @return_value.should == :new_return_value
363
- @args.should == [:original_return_value]
364
- end
365
- end
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
- describe DoubleDefinition, "#times", :shared => true do
368
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
371
- @definition.times(3).should === @definition
372
- end
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
- it "sets up a Times Called Expectation with passed in times" do
375
- proc {@object.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
376
- end
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
- def create_definition
379
- actual_args = nil
380
- @definition.with(1, 2).times(3) do |*args|
381
- actual_args = args
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
- describe DoubleDefinition, "#times with returns block_callback_strategy" do
392
- it_should_behave_like "RR::DoubleDefinition#times"
393
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
396
- @return_value.should == :new_return_value
397
- @args.should == [1, 2]
398
- end
399
- end
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
- describe DoubleDefinition, "#times with after_call block_callback_strategy" do
402
- it_should_behave_like "RR::DoubleDefinition#times"
403
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
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
- it "sets return value when block passed in" do
406
- @return_value.should == :new_return_value
407
- @args.should == [:original_return_value]
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
- it "returns DoubleDefinition" do
415
- @definition.any_number_of_times.should === @definition
416
- end
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
- it "sets up a Times Called Expectation with AnyTimes matcher" do
419
- @definition.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
420
- end
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
- def create_definition
423
- actual_args = nil
424
- @definition.with(1, 2).any_number_of_times do |*args|
425
- actual_args = args
426
- :new_return_value
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
- describe DoubleDefinition, "#any_number_of_times with returns block_callback_strategy" do
435
- it_should_behave_like "RR::DoubleDefinition#any_number_of_times"
436
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
439
- @return_value.should == :new_return_value
440
- @args.should == [1, 2]
441
- end
442
- end
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
- describe DoubleDefinition, "#any_number_of_times with after_call block_callback_strategy" do
445
- it_should_behave_like "RR::DoubleDefinition#any_number_of_times"
446
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
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
- it "sets return value when block passed in" do
449
- @return_value.should == :new_return_value
450
- @args.should == [:original_return_value]
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
- describe DoubleDefinition, "#ordered", :shared => true do
455
- it_should_behave_like "RR::DoubleDefinition"
456
-
457
- it "adds itself to the ordered doubles list" do
458
- @definition.ordered
459
- @space.ordered_doubles.should include(@double)
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
- it "does not double_injection add itself" do
463
- @definition.ordered
464
- @space.ordered_doubles.should == [@double]
465
- end
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
- it "sets ordered? to true" do
468
- @definition.should be_ordered
469
- end
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
- it "raises error when there is no Double" do
472
- @definition.double = nil
473
- proc do
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
- def create_definition
484
- actual_args = nil
485
- @definition.with(1, 2).once.ordered do |*args|
486
- actual_args = args
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
- describe DoubleDefinition, "#ordered with returns block_callback_strategy" do
495
- it_should_behave_like "RR::DoubleDefinition#ordered"
496
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
499
- @return_value.should == :new_return_value
500
- @args.should == [1, 2]
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
- describe DoubleDefinition, "#ordered with after_call block_callback_strategy" do
505
- it_should_behave_like "RR::DoubleDefinition#ordered"
506
- it_should_behave_like "RR::DoubleDefinition with after_call block_callback_strategy"
507
-
508
- it "sets return value when block passed in" do
509
- @return_value.should == :new_return_value
510
- @args.should == [:original_return_value]
511
- end
512
- end
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
- describe DoubleDefinition, "#ordered?" do
515
- it_should_behave_like "RR::DoubleDefinition"
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
- it "defaults to false" do
518
- @definition.should_not be_ordered
519
- end
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
- describe DoubleDefinition, "#yields", :shared => true do
523
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
526
- @definition.yields(:baz).should === @definition
527
- end
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
- it "yields the passed in argument to the call block when there is a no returns value set" do
530
- @passed_in_block_arg.should == :baz
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
- def create_definition
534
- actual_args = nil
535
- @definition.with(1, 2).once.yields(:baz) do |*args|
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
- describe DoubleDefinition, "#yields with returns block_callback_strategy" do
550
- it_should_behave_like "RR::DoubleDefinition#yields"
551
- it_should_behave_like "RR::DoubleDefinition with returns block_callback_strategy"
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
- it "sets return value when block passed in" do
554
- @return_value.should == :new_return_value
555
- @args.length.should == 3
556
- @args[0..1].should == [1, 2]
557
- @args[2].should be_instance_of(Proc)
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
- it "sets return value when block passed in" do
566
- @return_value.should == :new_return_value
567
- @args.should == [:original_return_value]
568
- end
569
- end
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
- describe DoubleDefinition, "#after_call" do
572
- it_should_behave_like "RR::DoubleDefinition"
563
+ @args = actual_args
564
+ end
573
565
 
574
- it "returns DoubleDefinition" do
575
- @definition.after_call {}.should === @definition
576
- end
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
- it "sends return value of Double implementation to after_call" do
579
- return_value = {}
580
- @definition.with_any_args.returns(return_value).after_call do |value|
581
- value[:foo] = :bar
582
- value
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
- actual_value = @object.foobar
586
- actual_value.should === return_value
587
- actual_value.should == {:foo => :bar}
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
- it "receives the return value in the after_call callback" do
591
- return_value = :returns_value
592
- @definition.with_any_args.returns(return_value).after_call do |value|
593
- :after_call_value
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
- it "allows after_call to mock the return value" do
601
- return_value = Object.new
602
- @definition.with_any_args.returns(return_value).after_call do |value|
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
- @object.foobar.inner_method(1).should == :baz
608
- end
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
- it "raises an error when not passed a block" do
611
- proc do
612
- @definition.after_call
613
- end.should raise_error(ArgumentError, "after_call expects a block")
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
- describe DoubleDefinition, "#returns" do
618
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns DoubleDefinition" do
621
- @definition.returns {:baz}.should === @definition
622
- @definition.returns(:baz).should === @definition
623
- end
612
+ actual_value = @object.foobar
613
+ actual_value.should == :after_call_value
614
+ end
624
615
 
625
- it "sets the value of the method when passed a block" do
626
- @definition.with_any_args.returns {:baz}
627
- @object.foobar.should == :baz
628
- end
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
- it "sets the value of the method when passed an argument" do
631
- @definition.returns(:baz).with_no_args
632
- @object.foobar.should == :baz
633
- end
623
+ @object.foobar.inner_method(1).should == :baz
624
+ end
634
625
 
635
- it "returns false when passed false" do
636
- @definition.returns(false).with_any_args
637
- @object.foobar.should == false
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
- it "raises an error when both argument and block is passed in" do
641
- proc do
642
- @definition.returns(:baz) {:another}
643
- end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
644
- end
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
- describe DoubleDefinition, "#implemented_by" do
648
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns the DoubleDefinition" do
651
- @definition.implemented_by(proc{:baz}).should === @definition
652
- end
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
- it "sets the implementation to the passed in proc" do
655
- @definition.implemented_by(proc{:baz}).with_no_args
656
- @object.foobar.should == :baz
657
- end
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
- it "sets the implementation to the passed in method" do
660
- def @object.foobar(a, b)
661
- [b, a]
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
- describe DoubleDefinition, "#implemented_by_original_method" do
669
- it_should_behave_like "RR::DoubleDefinition"
670
-
671
- it "returns the DoubleDefinition object" do
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
- it "sets the implementation to the original method" do
676
- @definition.implemented_by_original_method.with_any_args
677
- @object.foobar(1, 2).should == :original_return_value
678
- end
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
- it "calls method_missing when original_method does not exist" do
681
- class << @object
682
- def method_missing(method_name, *args, &block)
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
- it "returns false when arguments are not an exact match" do
707
- @definition.with(1, 2, 3)
708
- @definition.should_not be_exact_match(1, 2)
709
- @definition.should_not be_exact_match(1)
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
- it "returns true when arguments are an exact match" do
715
- @definition.with(1, 2, 3)
716
- @definition.should be_exact_match(1, 2, 3)
717
- end
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
- describe DoubleDefinition, "#wildcard_match?" do
721
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns false when no expectation set" do
724
- @definition.should_not be_wildcard_match()
725
- @definition.should_not be_wildcard_match(nil)
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
- it "returns true when arguments are an exact match" do
731
- @definition.with(1, 2, 3)
732
- @definition.should be_wildcard_match(1, 2, 3)
733
- @definition.should_not be_wildcard_match(1, 2)
734
- @definition.should_not be_wildcard_match(1)
735
- @definition.should_not be_wildcard_match()
736
- @definition.should_not be_wildcard_match("does not match")
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
- it "returns true when with_any_args" do
740
- @definition.with_any_args
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
- @definition.should be_wildcard_match(1, 2, 3)
743
- @definition.should be_wildcard_match(1, 2)
744
- @definition.should be_wildcard_match(1)
745
- @definition.should be_wildcard_match()
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
- describe DoubleDefinition, "#terminal?" do
751
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns true when times_matcher's terminal? is true" do
754
- @definition.once
755
- @definition.times_matcher.should be_terminal
756
- @definition.should be_terminal
757
- end
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
- it "returns false when times_matcher's terminal? is false" do
760
- @definition.any_number_of_times
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
- it "returns false when there is not times_matcher" do
766
- @definition.times_matcher.should be_nil
767
- @definition.should_not be_terminal
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
- describe DoubleDefinition, "#expected_arguments" do
772
- it_should_behave_like "RR::DoubleDefinition"
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
- it "returns argument expectation's expected_arguments when there is a argument expectation" do
775
- @definition.with(1, 2)
776
- @definition.expected_arguments.should == [1, 2]
777
- end
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
- it "returns an empty array when there is no argument expectation" do
780
- @definition.argument_expectation.should be_nil
781
- @definition.expected_arguments.should == []
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
- describe DoubleDefinition, "#block_callback_strategy" do
786
- it_should_behave_like "RR::DoubleDefinition"
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
- it "defaults to :returns" do
789
- @definition.block_callback_strategy.should == :returns
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
- it "sets the block_callback_strategy to :returns" do
797
- @definition.returns_block_callback_strategy!
798
- @definition.block_callback_strategy.should == :returns
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
- describe DoubleDefinition, "#after_call_block_callback_strategy!" do
803
- it_should_behave_like "RR::DoubleDefinition"
804
-
805
- it "sets the block_callback_strategy to :after_call" do
806
- @definition.after_call_block_callback_strategy!
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
- describe DoubleDefinition, "#verbose" do
812
- it_should_behave_like "RR::DoubleDefinition"
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
- it "sets the verbose? to true" do
815
- @definition.should_not be_verbose
816
- @definition.verbose
817
- @definition.should be_verbose
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