rr 0.10.10 → 0.10.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGES +4 -0
  2. data/VERSION.yml +1 -1
  3. data/lib/rr.rb +5 -3
  4. data/lib/rr/adapters/rr_methods.rb +5 -5
  5. data/lib/rr/blank_slate.rb +17 -0
  6. data/lib/rr/double_definitions/{child_double_definition_creator.rb → child_double_definition_create.rb} +1 -1
  7. data/lib/rr/double_definitions/double_definition.rb +13 -11
  8. data/lib/rr/double_definitions/{double_definition_creator.rb → double_definition_create.rb} +52 -43
  9. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
  10. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +2 -2
  11. data/lib/rr/double_definitions/strategies/scope/instance.rb +1 -1
  12. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +6 -6
  13. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +2 -2
  14. data/lib/rr/double_definitions/strategies/strategy.rb +15 -16
  15. data/lib/rr/double_definitions/strategies/verification/mock.rb +1 -1
  16. data/lib/rr/double_definitions/strategies/verification/stub.rb +1 -1
  17. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +2 -2
  18. data/lib/rr/injections/double_injection.rb +59 -4
  19. data/lib/rr/injections/injection.rb +6 -0
  20. data/lib/rr/injections/method_missing_injection.rb +13 -1
  21. data/lib/rr/injections/singleton_method_added_injection.rb +14 -3
  22. data/lib/rr/method_dispatches/base_method_dispatch.rb +2 -2
  23. data/lib/rr/method_dispatches/method_missing_dispatch.rb +2 -2
  24. data/lib/rr/recorded_calls.rb +1 -1
  25. data/lib/rr/space.rb +17 -68
  26. data/lib/rr/spy_verification_proxy.rb +1 -6
  27. data/spec/rr/adapters/rr_methods_creator_spec.rb +9 -21
  28. data/spec/rr/adapters/rr_methods_space_spec.rb +10 -25
  29. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +16 -16
  30. data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +87 -0
  31. data/spec/rr/double_definitions/{double_definition_creator_spec.rb → double_definition_create_spec.rb} +64 -72
  32. data/spec/rr/double_injection/double_injection_verify_spec.rb +2 -2
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +5 -29
  34. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +7 -39
  35. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +19 -47
  36. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +1 -9
  37. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +18 -64
  38. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +7 -53
  39. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +12 -56
  40. data/spec/rr/rspec/rspec_adapter_spec.rb +8 -11
  41. data/spec/rr/space/space_spec.rb +72 -212
  42. data/spec/spec_helper.rb +0 -76
  43. data/spec/spy_verification_spec.rb +1 -1
  44. metadata +8 -11
  45. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +0 -37
  46. data/ruby_19_spec.rb +0 -12
  47. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +0 -124
  48. data/spec/rr/double_definitions/double_definition_spec.rb +0 -1168
  49. data/spec/rr/double_spec.rb +0 -361
  50. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +0 -38
@@ -14,11 +14,11 @@ module RR
14
14
  end
15
15
 
16
16
  it "resets the double_injections" do
17
- RR.double_injection(subject, method_name)
18
- RR.double_injections.should_not be_empty
17
+ stub(subject).foobar
18
+ Injections::DoubleInjection.instances.should_not be_empty
19
19
 
20
20
  fixture.setup_mocks_for_rspec
21
- RR.double_injections.should be_empty
21
+ Injections::DoubleInjection.instances.should be_empty
22
22
  end
23
23
  end
24
24
 
@@ -32,15 +32,12 @@ module RR
32
32
  end
33
33
 
34
34
  it "verifies the double_injections" do
35
- double_injection = RR.double_injection(subject, method_name)
36
- double = new_double(double_injection)
37
-
38
- double.definition.once
35
+ mock(subject).foobar
39
36
 
40
37
  lambda do
41
38
  fixture.verify_mocks_for_rspec
42
39
  end.should raise_error(::RR::Errors::TimesCalledError)
43
- RR.double_injections.should be_empty
40
+ Injections::DoubleInjection.instances.should be_empty
44
41
  end
45
42
  end
46
43
 
@@ -54,11 +51,11 @@ module RR
54
51
  end
55
52
 
56
53
  it "resets the double_injections" do
57
- RR.double_injection(subject, method_name)
58
- RR.double_injections.should_not be_empty
54
+ stub(subject).foobar
55
+ Injections::DoubleInjection.instances.should_not be_empty
59
56
 
60
57
  fixture.teardown_mocks_for_rspec
61
- RR.double_injections.should be_empty
58
+ Injections::DoubleInjection.instances.should be_empty
62
59
  end
63
60
  end
64
61
  end
@@ -9,23 +9,6 @@ module RR
9
9
  @subject = Object.new
10
10
  end
11
11
 
12
- describe ".method_missing" do
13
- it "proxies to a singleton instance of Space" do
14
- create_double_args = nil
15
- (
16
- class << space;
17
- self;
18
- end).class_eval do
19
- define_method :double_injection do |*args|
20
- create_double_args = args
21
- end
22
- end
23
-
24
- space.double_injection(:foo, :bar)
25
- create_double_args.should == [:foo, :bar]
26
- end
27
- end
28
-
29
12
  describe "#record_call" do
30
13
  it "should add a call to the list" do
31
14
  object = Object.new
@@ -43,8 +26,8 @@ module RR
43
26
  (subject_1 === subject_2).should be_true
44
27
  subject_1.__id__.should_not == subject_2.__id__
45
28
 
46
- injection_1 = space.double_injection(subject_1, :foobar)
47
- injection_2 = space.double_injection(subject_2, :foobar)
29
+ injection_1 = Injections::DoubleInjection.create(subject_1, :foobar)
30
+ injection_2 = Injections::DoubleInjection.create(subject_2, :foobar)
48
31
 
49
32
  injection_1.should_not == injection_2
50
33
  end
@@ -61,8 +44,8 @@ module RR
61
44
 
62
45
  context "when method_name is a symbol" do
63
46
  it "returns double_injection and adds double_injection to double_injection list" do
64
- double_injection = space.double_injection(subject, method_name)
65
- space.double_injection(subject, method_name).should === double_injection
47
+ double_injection = Injections::DoubleInjection.create(subject, method_name)
48
+ Injections::DoubleInjection.create(subject, method_name).should === double_injection
66
49
  double_injection.subject.should === subject
67
50
  double_injection.method_name.should === method_name
68
51
  end
@@ -70,8 +53,8 @@ module RR
70
53
 
71
54
  context "when method_name is a string" do
72
55
  it "returns double_injection and adds double_injection to double_injection list" do
73
- double_injection = space.double_injection(subject, 'foobar')
74
- space.double_injection(subject, method_name).should === double_injection
56
+ double_injection = Injections::DoubleInjection.create(subject, 'foobar')
57
+ Injections::DoubleInjection.create(subject, method_name).should === double_injection
75
58
  double_injection.subject.should === subject
76
59
  double_injection.method_name.should === method_name
77
60
  end
@@ -79,7 +62,7 @@ module RR
79
62
 
80
63
  it "overrides the method when passing a block" do
81
64
  original_method = subject.method(:foobar)
82
- space.double_injection(subject, method_name)
65
+ Injections::DoubleInjection.create(subject, method_name)
83
66
  subject.method(:foobar).should_not == original_method
84
67
  end
85
68
  end
@@ -95,11 +78,11 @@ module RR
95
78
 
96
79
  context "when a DoubleInjection is registered for the subject and method_name" do
97
80
  it "returns the existing DoubleInjection" do
98
- @double_injection = space.double_injection(subject, 'foobar')
81
+ @double_injection = Injections::DoubleInjection.create(subject, 'foobar')
99
82
 
100
83
  double_injection.subject_has_original_method?.should be_true
101
84
 
102
- space.double_injection(subject, 'foobar').should === double_injection
85
+ Injections::DoubleInjection.create(subject, 'foobar').should === double_injection
103
86
 
104
87
  double_injection.reset
105
88
  subject.foobar.should == :original_foobar
@@ -116,8 +99,8 @@ module RR
116
99
  (subject_1 === subject_2).should be_true
117
100
  subject_1.__id__.should_not == subject_2.__id__
118
101
 
119
- injection_1 = space.method_missing_injection(subject_1)
120
- injection_2 = space.method_missing_injection(subject_2)
102
+ injection_1 = Injections::MethodMissingInjection.create(subject_1)
103
+ injection_2 = Injections::MethodMissingInjection.create(subject_2)
121
104
 
122
105
  injection_1.should_not == injection_2
123
106
  end
@@ -132,7 +115,7 @@ module RR
132
115
 
133
116
  it "overrides the method when passing a block" do
134
117
  original_method = subject.method(:method_missing)
135
- space.method_missing_injection(subject)
118
+ Injections::MethodMissingInjection.create(subject)
136
119
  subject.method(:method_missing).should_not == original_method
137
120
  end
138
121
  end
@@ -146,10 +129,10 @@ module RR
146
129
 
147
130
  context "when a DoubleInjection is registered for the subject and method_name" do
148
131
  it "returns the existing DoubleInjection" do
149
- injection = space.method_missing_injection(subject)
132
+ injection = Injections::MethodMissingInjection.create(subject)
150
133
  injection.subject_has_original_method?.should be_true
151
134
 
152
- space.method_missing_injection(subject).should === injection
135
+ Injections::MethodMissingInjection.create(subject).should === injection
153
136
 
154
137
  injection.reset
155
138
  subject.method_missing(:foobar).should == :original_method_missing
@@ -166,8 +149,8 @@ module RR
166
149
  (subject_1 === subject_2).should be_true
167
150
  subject_1.__id__.should_not == subject_2.__id__
168
151
 
169
- injection_1 = space.singleton_method_added_injection(subject_1)
170
- injection_2 = space.singleton_method_added_injection(subject_2)
152
+ injection_1 = Injections::SingletonMethodAddedInjection.create(subject_1)
153
+ injection_2 = Injections::SingletonMethodAddedInjection.create(subject_2)
171
154
 
172
155
  injection_1.should_not == injection_2
173
156
  end
@@ -182,7 +165,7 @@ module RR
182
165
 
183
166
  it "overrides the method when passing a block" do
184
167
  original_method = subject.method(:singleton_method_added)
185
- space.singleton_method_added_injection(subject)
168
+ Injections::SingletonMethodAddedInjection.create(subject)
186
169
  subject.method(:singleton_method_added).should_not == original_method
187
170
  end
188
171
  end
@@ -196,10 +179,10 @@ module RR
196
179
 
197
180
  context "when a DoubleInjection is registered for the subject and method_name" do
198
181
  it "returns the existing DoubleInjection" do
199
- injection = space.singleton_method_added_injection(subject)
182
+ injection = Injections::SingletonMethodAddedInjection.create(subject)
200
183
  injection.subject_has_original_method?.should be_true
201
184
 
202
- space.singleton_method_added_injection(subject).should === injection
185
+ Injections::SingletonMethodAddedInjection.create(subject).should === injection
203
186
 
204
187
  injection.reset
205
188
  subject.singleton_method_added(:foobar).should == :original_singleton_method_added
@@ -225,16 +208,8 @@ module RR
225
208
  end
226
209
 
227
210
  it "removes the ordered doubles" do
228
- double_1 = new_double(
229
- space.double_injection(subject_1, :foobar1),
230
- RR::DoubleDefinitions::DoubleDefinition.new(creator = Object.new, subject_1)
231
- )
232
- double_2 = new_double(
233
- space.double_injection(subject_2, :foobar2),
234
- RR::DoubleDefinitions::DoubleDefinition.new(creator = Object.new, subject_2)
235
- )
236
- double_1.definition.ordered
237
- double_2.definition.ordered
211
+ mock(subject_1).foobar1.ordered
212
+ mock(subject_2).foobar2.ordered
238
213
 
239
214
  space.ordered_doubles.should_not be_empty
240
215
 
@@ -246,63 +221,63 @@ module RR
246
221
  subject_1.respond_to?(method_name).should be_false
247
222
  subject_2.respond_to?(method_name).should be_false
248
223
 
249
- space.double_injection(subject_1, method_name)
250
- space.double_injection_exists?(subject_1, method_name).should be_true
224
+ Injections::DoubleInjection.create(subject_1, method_name)
225
+ Injections::DoubleInjection.exists?(subject_1, method_name).should be_true
251
226
  subject_1.respond_to?(method_name).should be_true
252
227
 
253
- space.double_injection(subject_2, method_name)
254
- space.double_injection_exists?(subject_2, method_name).should be_true
228
+ Injections::DoubleInjection.create(subject_2, method_name)
229
+ Injections::DoubleInjection.exists?(subject_2, method_name).should be_true
255
230
  subject_2.respond_to?(method_name).should be_true
256
231
 
257
232
  space.reset
258
233
 
259
234
  subject_1.respond_to?(method_name).should be_false
260
- space.double_injection_exists?(subject_1, method_name).should be_false
235
+ Injections::DoubleInjection.exists?(subject_1, method_name).should be_false
261
236
 
262
237
  subject_2.respond_to?(method_name).should be_false
263
- space.double_injection_exists?(subject_2, method_name).should be_false
238
+ Injections::DoubleInjection.exists?(subject_2, method_name).should be_false
264
239
  end
265
240
 
266
241
  it "resets all method_missing_injections" do
267
242
  subject_1.respond_to?(:method_missing).should be_false
268
243
  subject_2.respond_to?(:method_missing).should be_false
269
244
 
270
- space.method_missing_injection(subject_1)
271
- space.method_missing_injection_exists?(subject_1).should be_true
245
+ Injections::MethodMissingInjection.create(subject_1)
246
+ Injections::MethodMissingInjection.exists?(subject_1).should be_true
272
247
  subject_1.respond_to?(:method_missing).should be_true
273
248
 
274
- space.method_missing_injection(subject_2)
275
- space.method_missing_injection_exists?(subject_2).should be_true
249
+ Injections::MethodMissingInjection.create(subject_2)
250
+ Injections::MethodMissingInjection.exists?(subject_2).should be_true
276
251
  subject_2.respond_to?(:method_missing).should be_true
277
252
 
278
253
  space.reset
279
254
 
280
255
  subject_1.respond_to?(:method_missing).should be_false
281
- space.method_missing_injection_exists?(subject_1).should be_false
256
+ Injections::MethodMissingInjection.exists?(subject_1).should be_false
282
257
 
283
258
  subject_2.respond_to?(:method_missing).should be_false
284
- space.method_missing_injection_exists?(subject_2).should be_false
259
+ Injections::MethodMissingInjection.exists?(subject_2).should be_false
285
260
  end
286
261
 
287
262
  it "resets all singleton_method_added_injections" do
288
263
  subject_1.respond_to?(:singleton_method_added).should be_false
289
264
  subject_2.respond_to?(:singleton_method_added).should be_false
290
265
 
291
- space.singleton_method_added_injection(subject_1)
292
- space.singleton_method_added_injection_exists?(subject_1).should be_true
266
+ Injections::SingletonMethodAddedInjection.create(subject_1)
267
+ Injections::SingletonMethodAddedInjection.exists?(subject_1).should be_true
293
268
  subject_1.respond_to?(:singleton_method_added).should be_true
294
269
 
295
- space.singleton_method_added_injection(subject_2)
296
- space.singleton_method_added_injection_exists?(subject_2).should be_true
270
+ Injections::SingletonMethodAddedInjection.create(subject_2)
271
+ Injections::SingletonMethodAddedInjection.exists?(subject_2).should be_true
297
272
  subject_2.respond_to?(:singleton_method_added).should be_true
298
273
 
299
274
  space.reset
300
275
 
301
276
  subject_1.respond_to?(:singleton_method_added).should be_false
302
- space.singleton_method_added_injection_exists?(subject_1).should be_false
277
+ Injections::SingletonMethodAddedInjection.exists?(subject_1).should be_false
303
278
 
304
279
  subject_2.respond_to?(:singleton_method_added).should be_false
305
- space.singleton_method_added_injection_exists?(subject_2).should be_false
280
+ Injections::SingletonMethodAddedInjection.exists?(subject_2).should be_false
306
281
  end
307
282
  end
308
283
 
@@ -317,36 +292,37 @@ module RR
317
292
  it "resets the double_injections and restores the original method" do
318
293
  original_method = subject.method(method_name)
319
294
 
320
- @double_injection = space.double_injection(subject, method_name)
321
- space.double_injections[subject][method_name].should === double_injection
295
+ @double_injection = Injections::DoubleInjection.create(subject, method_name)
296
+ Injections::DoubleInjection.instances.keys.should include(subject)
297
+ Injections::DoubleInjection.instances[subject].keys.should include(method_name)
322
298
  subject.method(method_name).should_not == original_method
323
299
 
324
300
  space.reset_double(subject, method_name)
325
- space.double_injections[subject][method_name].should be_nil
301
+ Injections::DoubleInjection.instances.keys.should_not include(subject)
326
302
  subject.method(method_name).should == original_method
327
303
  end
328
304
 
329
305
  context "when it has no double_injections" do
330
306
  it "removes the subject from the double_injections map" do
331
- double_1 = space.double_injection(subject, :foobar1)
332
- double_2 = space.double_injection(subject, :foobar2)
307
+ double_1 = Injections::DoubleInjection.create(subject, :foobar1)
308
+ double_2 = Injections::DoubleInjection.create(subject, :foobar2)
333
309
 
334
- space.double_injections.include?(subject).should == true
335
- space.double_injections[subject][:foobar1].should_not be_nil
336
- space.double_injections[subject][:foobar2].should_not be_nil
310
+ Injections::DoubleInjection.instances.include?(subject).should == true
311
+ Injections::DoubleInjection.instances[subject][:foobar1].should_not be_nil
312
+ Injections::DoubleInjection.instances[subject][:foobar2].should_not be_nil
337
313
 
338
314
  space.reset_double(subject, :foobar1)
339
- space.double_injections.include?(subject).should == true
340
- space.double_injections[subject][:foobar1].should be_nil
341
- space.double_injections[subject][:foobar2].should_not be_nil
315
+ Injections::DoubleInjection.instances.include?(subject).should == true
316
+ Injections::DoubleInjection.instances[subject][:foobar1].should be_nil
317
+ Injections::DoubleInjection.instances[subject][:foobar2].should_not be_nil
342
318
 
343
319
  space.reset_double(subject, :foobar2)
344
- space.double_injections.include?(subject).should == false
320
+ Injections::DoubleInjection.instances.include?(subject).should == false
345
321
  end
346
322
  end
347
323
  end
348
324
 
349
- describe "#reset_double_injections" do
325
+ describe "#DoubleInjection.reset" do
350
326
  attr_reader :subject_1, :subject_2
351
327
  before do
352
328
  @subject_1 = Object.new
@@ -355,52 +331,27 @@ module RR
355
331
  end
356
332
 
357
333
  it "resets the double_injection and removes it from the double_injections list" do
358
- double_injection_1 = space.double_injection(subject_1, method_name)
334
+ double_injection_1 = Injections::DoubleInjection.create(subject_1, method_name)
359
335
  double_1_reset_call_count = 0
360
- (
361
- class << double_injection_1;
362
- self;
363
- end).class_eval do
336
+ ( class << double_injection_1; self; end).class_eval do
364
337
  define_method(:reset) do
365
338
  double_1_reset_call_count += 1
366
339
  end
367
340
  end
368
- double_injection_2 = space.double_injection(subject_2, method_name)
341
+ double_injection_2 = Injections::DoubleInjection.create(subject_2, method_name)
369
342
  double_2_reset_call_count = 0
370
- (
371
- class << double_injection_2;
372
- self;
373
- end).class_eval do
343
+ ( class << double_injection_2; self; end).class_eval do
374
344
  define_method(:reset) do
375
345
  double_2_reset_call_count += 1
376
346
  end
377
347
  end
378
348
 
379
- space.__send__(:reset_double_injections)
349
+ Injections::DoubleInjection.reset
380
350
  double_1_reset_call_count.should == 1
381
351
  double_2_reset_call_count.should == 1
382
352
  end
383
353
  end
384
354
 
385
- describe "#register_ordered_double" do
386
- before(:each) do
387
- @method_name = :foobar
388
- @double_injection = space.double_injection(subject, method_name)
389
- end
390
-
391
- it "adds the ordered double to the ordered_doubles collection" do
392
- double_1 = new_double
393
-
394
- space.ordered_doubles.should == []
395
- space.register_ordered_double double_1
396
- space.ordered_doubles.should == [double_1]
397
-
398
- double_2 = new_double
399
- space.register_ordered_double double_2
400
- space.ordered_doubles.should == [double_1, double_2]
401
- end
402
- end
403
-
404
355
  describe "#verify_doubles" do
405
356
  attr_reader :subject_1, :subject_2, :subject3, :double_1, :double_2, :double3
406
357
  before do
@@ -408,9 +359,9 @@ module RR
408
359
  @subject_2 = Object.new
409
360
  @subject3 = Object.new
410
361
  @method_name = :foobar
411
- @double_1 = space.double_injection(subject_1, method_name)
412
- @double_2 = space.double_injection(subject_2, method_name)
413
- @double3 = space.double_injection(subject3, method_name)
362
+ @double_1 = Injections::DoubleInjection.create(subject_1, method_name)
363
+ @double_2 = Injections::DoubleInjection.create(subject_2, method_name)
364
+ @double3 = Injections::DoubleInjection.create(subject3, method_name)
414
365
  end
415
366
 
416
367
  context "when passed no arguments" do
@@ -549,10 +500,7 @@ module RR
549
500
  it "does not raise an error" do
550
501
  double_1_verify_call_count = 0
551
502
  double_1_reset_call_count = 0
552
- (
553
- class << double_1;
554
- self;
555
- end).class_eval do
503
+ ( class << double_1; self; end).class_eval do
556
504
  define_method(:verify) do
557
505
  double_1_verify_call_count += 1
558
506
  end
@@ -563,10 +511,7 @@ module RR
563
511
 
564
512
  double_2_verify_call_count = 0
565
513
  double_2_reset_call_count = 0
566
- (
567
- class << double_2;
568
- self;
569
- end).class_eval do
514
+ ( class << double_2; self; end).class_eval do
570
515
  define_method(:verify) do
571
516
  double_2_verify_call_count += 1
572
517
  end
@@ -577,10 +522,7 @@ module RR
577
522
 
578
523
  double3_verify_call_count = 0
579
524
  double3_reset_call_count = 0
580
- (
581
- class << double3;
582
- self;
583
- end).class_eval do
525
+ ( class << double3; self; end).class_eval do
584
526
  define_method(:verify) do
585
527
  double3_verify_call_count += 1
586
528
  end
@@ -611,14 +553,11 @@ module RR
611
553
  end
612
554
 
613
555
  it "verifies and deletes the double_injection" do
614
- @double_injection = space.double_injection(subject, method_name)
615
- space.double_injections[subject][method_name].should === double_injection
556
+ @double_injection = Injections::DoubleInjection.create(subject, method_name)
557
+ Injections::DoubleInjection.instances[subject][method_name].should === double_injection
616
558
 
617
559
  verify_call_count = 0
618
- (
619
- class << double_injection;
620
- self;
621
- end).class_eval do
560
+ ( class << double_injection; self; end).class_eval do
622
561
  define_method(:verify) do
623
562
  verify_call_count += 1
624
563
  end
@@ -626,23 +565,20 @@ module RR
626
565
  space.verify_double(subject, method_name)
627
566
  verify_call_count.should == 1
628
567
 
629
- space.double_injections[subject][method_name].should be_nil
568
+ Injections::DoubleInjection.instances[subject][method_name].should be_nil
630
569
  end
631
570
 
632
571
  context "when verifying the double_injection raises an error" do
633
572
  it "deletes the double_injection and restores the original method" do
634
573
  original_method = subject.method(method_name)
635
574
 
636
- @double_injection = space.double_injection(subject, method_name)
575
+ @double_injection = Injections::DoubleInjection.create(subject, method_name)
637
576
  subject.method(method_name).should_not == original_method
638
577
 
639
- space.double_injections[subject][method_name].should === double_injection
578
+ Injections::DoubleInjection.instances[subject][method_name].should === double_injection
640
579
 
641
580
  verify_called = true
642
- (
643
- class << double_injection;
644
- self;
645
- end).class_eval do
581
+ ( class << double_injection; self; end).class_eval do
646
582
  define_method(:verify) do
647
583
  verify_called = true
648
584
  raise "An Error"
@@ -651,86 +587,10 @@ module RR
651
587
  lambda {space.verify_double(subject, method_name)}.should raise_error
652
588
  verify_called.should be_true
653
589
 
654
- space.double_injections[subject][method_name].should be_nil
590
+ Injections::DoubleInjection.instances[subject][method_name].should be_nil
655
591
  subject.method(method_name).should == original_method
656
592
  end
657
593
  end
658
594
  end
659
-
660
- describe "#verify_ordered_double" do
661
- before do
662
- @method_name = :foobar
663
- @double_injection = space.double_injection(subject, method_name)
664
- end
665
-
666
- macro "#verify_ordered_double" do
667
- it "raises an error when Double is NonTerminal" do
668
- double = new_double
669
- space.register_ordered_double(double)
670
-
671
- double.definition.any_number_of_times
672
- double.should_not be_terminal
673
-
674
- lambda do
675
- space.verify_ordered_double(double)
676
- end.should raise_error(
677
- Errors::DoubleOrderError,
678
- "Ordered Doubles cannot have a NonTerminal TimesCalledExpectation"
679
- )
680
- end
681
- end
682
-
683
- context "when the passed in double is at the front of the queue" do
684
- send "#verify_ordered_double"
685
- it "keeps the double when times called is not verified" do
686
- double = new_double
687
- space.register_ordered_double(double)
688
-
689
- double.definition.twice
690
- double.should be_attempt
691
-
692
- space.verify_ordered_double(double)
693
- space.ordered_doubles.should include(double)
694
- end
695
-
696
- context "when Double#attempt? is false" do
697
- it "removes the double" do
698
- double = new_double
699
- space.register_ordered_double(double)
700
-
701
- double.definition.with(1).once
702
- subject.foobar(1)
703
- double.should_not be_attempt
704
-
705
- space.verify_ordered_double(double)
706
- space.ordered_doubles.should_not include(double)
707
- end
708
- end
709
- end
710
-
711
- context "when the passed in double is not at the front of the queue" do
712
- send "#verify_ordered_double"
713
- it "raises error" do
714
- first_double = new_double
715
- second_double = new_double
716
-
717
- lambda do
718
- space.verify_ordered_double(second_double)
719
- end.should raise_error(
720
- Errors::DoubleOrderError,
721
- "foobar() called out of order in list\n" <<
722
- "- foobar()\n" <<
723
- "- foobar()"
724
- )
725
- end
726
-
727
- def new_double
728
- double = super
729
- double.definition.once
730
- space.register_ordered_double(double)
731
- double
732
- end
733
- end
734
- end
735
595
  end
736
596
  end