rr 0.10.10 → 0.10.11
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 +4 -0
- data/VERSION.yml +1 -1
- data/lib/rr.rb +5 -3
- data/lib/rr/adapters/rr_methods.rb +5 -5
- data/lib/rr/blank_slate.rb +17 -0
- data/lib/rr/double_definitions/{child_double_definition_creator.rb → child_double_definition_create.rb} +1 -1
- data/lib/rr/double_definitions/double_definition.rb +13 -11
- data/lib/rr/double_definitions/{double_definition_creator.rb → double_definition_create.rb} +52 -43
- data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +2 -2
- data/lib/rr/double_definitions/strategies/scope/instance.rb +1 -1
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +6 -6
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +2 -2
- data/lib/rr/double_definitions/strategies/strategy.rb +15 -16
- data/lib/rr/double_definitions/strategies/verification/mock.rb +1 -1
- data/lib/rr/double_definitions/strategies/verification/stub.rb +1 -1
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +2 -2
- data/lib/rr/injections/double_injection.rb +59 -4
- data/lib/rr/injections/injection.rb +6 -0
- data/lib/rr/injections/method_missing_injection.rb +13 -1
- data/lib/rr/injections/singleton_method_added_injection.rb +14 -3
- data/lib/rr/method_dispatches/base_method_dispatch.rb +2 -2
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +2 -2
- data/lib/rr/recorded_calls.rb +1 -1
- data/lib/rr/space.rb +17 -68
- data/lib/rr/spy_verification_proxy.rb +1 -6
- data/spec/rr/adapters/rr_methods_creator_spec.rb +9 -21
- data/spec/rr/adapters/rr_methods_space_spec.rb +10 -25
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +16 -16
- data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +87 -0
- data/spec/rr/double_definitions/{double_definition_creator_spec.rb → double_definition_create_spec.rb} +64 -72
- data/spec/rr/double_injection/double_injection_verify_spec.rb +2 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +5 -29
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +7 -39
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +19 -47
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +1 -9
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +18 -64
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +7 -53
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +12 -56
- data/spec/rr/rspec/rspec_adapter_spec.rb +8 -11
- data/spec/rr/space/space_spec.rb +72 -212
- data/spec/spec_helper.rb +0 -76
- data/spec/spy_verification_spec.rb +1 -1
- metadata +8 -11
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +0 -37
- data/ruby_19_spec.rb +0 -12
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +0 -124
- data/spec/rr/double_definitions/double_definition_spec.rb +0 -1168
- data/spec/rr/double_spec.rb +0 -361
- 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
|
-
|
18
|
-
|
17
|
+
stub(subject).foobar
|
18
|
+
Injections::DoubleInjection.instances.should_not be_empty
|
19
19
|
|
20
20
|
fixture.setup_mocks_for_rspec
|
21
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
58
|
-
|
54
|
+
stub(subject).foobar
|
55
|
+
Injections::DoubleInjection.instances.should_not be_empty
|
59
56
|
|
60
57
|
fixture.teardown_mocks_for_rspec
|
61
|
-
|
58
|
+
Injections::DoubleInjection.instances.should be_empty
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
data/spec/rr/space/space_spec.rb
CHANGED
@@ -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 =
|
47
|
-
injection_2 =
|
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 =
|
65
|
-
|
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 =
|
74
|
-
|
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
|
-
|
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 =
|
81
|
+
@double_injection = Injections::DoubleInjection.create(subject, 'foobar')
|
99
82
|
|
100
83
|
double_injection.subject_has_original_method?.should be_true
|
101
84
|
|
102
|
-
|
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 =
|
120
|
-
injection_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
|
-
|
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 =
|
132
|
+
injection = Injections::MethodMissingInjection.create(subject)
|
150
133
|
injection.subject_has_original_method?.should be_true
|
151
134
|
|
152
|
-
|
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 =
|
170
|
-
injection_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
|
-
|
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 =
|
182
|
+
injection = Injections::SingletonMethodAddedInjection.create(subject)
|
200
183
|
injection.subject_has_original_method?.should be_true
|
201
184
|
|
202
|
-
|
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
|
-
|
229
|
-
|
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
|
-
|
250
|
-
|
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
|
-
|
254
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
271
|
-
|
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
|
-
|
275
|
-
|
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
|
-
|
256
|
+
Injections::MethodMissingInjection.exists?(subject_1).should be_false
|
282
257
|
|
283
258
|
subject_2.respond_to?(:method_missing).should be_false
|
284
|
-
|
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
|
-
|
292
|
-
|
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
|
-
|
296
|
-
|
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
|
-
|
277
|
+
Injections::SingletonMethodAddedInjection.exists?(subject_1).should be_false
|
303
278
|
|
304
279
|
subject_2.respond_to?(:singleton_method_added).should be_false
|
305
|
-
|
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 =
|
321
|
-
|
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
|
-
|
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 =
|
332
|
-
double_2 =
|
307
|
+
double_1 = Injections::DoubleInjection.create(subject, :foobar1)
|
308
|
+
double_2 = Injections::DoubleInjection.create(subject, :foobar2)
|
333
309
|
|
334
|
-
|
335
|
-
|
336
|
-
|
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
|
-
|
340
|
-
|
341
|
-
|
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
|
-
|
320
|
+
Injections::DoubleInjection.instances.include?(subject).should == false
|
345
321
|
end
|
346
322
|
end
|
347
323
|
end
|
348
324
|
|
349
|
-
describe "#
|
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 =
|
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 =
|
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
|
-
|
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 =
|
412
|
-
@double_2 =
|
413
|
-
@double3 =
|
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 =
|
615
|
-
|
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
|
-
|
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 =
|
575
|
+
@double_injection = Injections::DoubleInjection.create(subject, method_name)
|
637
576
|
subject.method(method_name).should_not == original_method
|
638
577
|
|
639
|
-
|
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
|
-
|
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
|