rr 0.4.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/CHANGES +14 -0
  2. data/README.rdoc +67 -13
  3. data/Rakefile +1 -1
  4. data/lib/rr.rb +29 -9
  5. data/lib/rr/adapters/rr_methods.rb +38 -158
  6. data/lib/rr/double.rb +46 -41
  7. data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
  8. data/lib/rr/double_definitions/double_definition.rb +212 -0
  9. data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
  10. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -0
  11. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  12. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  13. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  14. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  15. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -0
  16. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  17. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  18. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  19. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  20. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  21. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  22. data/lib/rr/double_injection.rb +21 -15
  23. data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
  24. data/lib/rr/space.rb +23 -22
  25. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  26. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  27. data/spec/high_level_spec.rb +111 -64
  28. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
  29. data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
  30. data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
  31. data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
  32. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
  33. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
  34. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
  35. data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
  36. data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
  37. data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
  38. data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
  39. data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
  40. data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
  41. data/spec/rr/double_injection/double_injection_spec.rb +77 -0
  42. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  43. data/spec/rr/double_spec.rb +156 -136
  44. data/spec/rr/errors/rr_error_spec.rb +1 -1
  45. data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
  46. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
  47. data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
  48. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
  49. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  50. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  51. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  52. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  53. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +30 -28
  54. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
  55. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
  56. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
  57. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
  58. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
  59. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
  60. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
  61. data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
  62. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
  63. data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
  64. data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
  65. data/spec/rr/space/space_spec.rb +330 -192
  66. data/spec/rr/test_unit/test_helper.rb +1 -2
  67. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
  68. data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
  69. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
  70. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
  71. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
  72. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
  73. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
  74. data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
  75. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
  76. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  77. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  78. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  79. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  80. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  81. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  82. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  83. data/spec/rr_spec.rb +28 -0
  84. data/spec/spec_helper.rb +84 -0
  85. metadata +43 -29
  86. data/lib/rr/double_creator.rb +0 -271
  87. data/lib/rr/double_definition.rb +0 -179
  88. data/lib/rr/double_definition_builder.rb +0 -44
  89. data/lib/rr/double_definition_creator.rb +0 -156
  90. data/lib/rr/double_definition_creator_proxy.rb +0 -20
  91. data/spec/rr/double/double_injection_bind_spec.rb +0 -105
  92. data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
  93. data/spec/rr/double/double_injection_reset_spec.rb +0 -86
  94. data/spec/rr/double/double_injection_spec.rb +0 -72
  95. data/spec/rr/double/double_injection_verify_spec.rb +0 -24
  96. data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
  97. data/spec/rr/double_definition_creator_spec.rb +0 -496
  98. data/spec/rr/double_definition_spec.rb +0 -815
  99. data/spec/rr/expectations/anything_spec.rb +0 -14
  100. data/spec/rr/expectations/boolean_spec.rb +0 -14
  101. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
  102. data/spec/rr/expectations/duck_type_spec.rb +0 -14
  103. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
  104. data/spec/rr/expectations/is_a_spec.rb +0 -14
  105. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
  106. data/spec/rr/expectations/numeric_spec.rb +0 -14
  107. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
  108. data/spec/rr/expectations/range_spec.rb +0 -10
  109. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
  110. data/spec/rr/expectations/regexp_spec.rb +0 -10
@@ -0,0 +1,77 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ describe DoubleInjection do
5
+ attr_reader :subject, :method_name, :double_injection
6
+ macro("sets up object and method_name") do
7
+ it "sets up object and method_name" do
8
+ double_injection.subject.should === subject
9
+ double_injection.method_name.should == method_name.to_sym
10
+ end
11
+ end
12
+
13
+ describe "#initialize" do
14
+ context "when method_name is a symbol" do
15
+ send("sets up object and method_name")
16
+
17
+ before do
18
+ @subject = Object.new
19
+ @method_name = :foobar
20
+ subject.methods.should_not include(method_name.to_s)
21
+ @double_injection = DoubleInjection.new(subject, method_name)
22
+ end
23
+ end
24
+
25
+ context "when method_name is a string" do
26
+ send("sets up object and method_name")
27
+
28
+ before do
29
+ @subject = Object.new
30
+ @method_name = 'foobar'
31
+ subject.methods.should_not include(method_name)
32
+ @double_injection = DoubleInjection.new(subject, method_name)
33
+ end
34
+ end
35
+
36
+ context "when method does not exist on object" do
37
+ send("sets up object and method_name")
38
+
39
+ before do
40
+ @subject = Object.new
41
+ @method_name = :foobar
42
+ subject.methods.should_not include(method_name.to_s)
43
+ @double_injection = DoubleInjection.new(subject, method_name)
44
+ end
45
+
46
+ it "object does not have original method" do
47
+ double_injection.object_has_original_method?.should be_false
48
+ end
49
+ end
50
+
51
+ context "when method exists on object" do
52
+ send("sets up object and method_name")
53
+
54
+ before do
55
+ @subject = Object.new
56
+ @method_name = :to_s
57
+ subject.methods.should include(method_name.to_s)
58
+ @double_injection = DoubleInjection.new(subject, method_name)
59
+ end
60
+
61
+ it "has a original_method" do
62
+ double_injection.object_has_original_method?.should be_true
63
+ end
64
+ end
65
+
66
+ context "when method_name is ==" do
67
+ send("sets up object and method_name")
68
+
69
+ before do
70
+ @subject = Object.new
71
+ @method_name = '=='
72
+ @double_injection = DoubleInjection.new(subject, method_name)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module DoubleDefinitions
5
+ describe DoubleInjection, "#verify" do
6
+ it_should_behave_like "Swapped Space"
7
+ attr_reader :space, :subject, :method_name, :double_injection
8
+ before do
9
+ @subject = Object.new
10
+ @method_name = :foobar
11
+ subject.methods.should_not include(method_name.to_s)
12
+ @double_injection = space.double_injection(subject, method_name)
13
+ end
14
+
15
+ it "verifies each double was met" do
16
+ double = Double.new(
17
+ double_injection,
18
+ DoubleDefinition.new(DoubleDefinitions::DoubleDefinitionCreator.new, subject)
19
+ )
20
+ double_injection.register_double double
21
+
22
+ double.with(1).once.returns {nil}
23
+ lambda {double_injection.verify}.should raise_error(Errors::TimesCalledError)
24
+ subject.foobar(1)
25
+ lambda {double_injection.verify}.should_not raise_error
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,17 +1,22 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
2
 
3
3
  module RR
4
4
  describe Double do
5
5
  it_should_behave_like "Swapped Space"
6
- attr_reader :space, :object, :double_injection, :double
6
+ attr_reader :subject, :double_injection, :definition, :definition_creator, :double
7
7
  before do
8
- @space = Space.instance
9
- @object = Object.new
10
- def object.foobar(a, b)
8
+ @subject = Object.new
9
+ def subject.foobar(a, b)
11
10
  [b, a]
12
11
  end
13
- @double_injection = space.double_injection(object, :foobar)
14
- @double = Double.new(double_injection)
12
+ @double_injection = create_double_injection
13
+ @definition_creator = DoubleDefinitions::DoubleDefinitionCreator.new
14
+ @definition = DoubleDefinitions::DoubleDefinition.new(definition_creator, subject)
15
+ @double = Double.new(double_injection, definition)
16
+ end
17
+
18
+ def create_double_injection
19
+ space.double_injection(subject, :foobar)
15
20
  end
16
21
 
17
22
  describe "#initialize" do
@@ -33,7 +38,7 @@ module RR
33
38
 
34
39
  it "sets return value when block passed in" do
35
40
  double.with(1) {:return_value}
36
- object.foobar(1).should == :return_value
41
+ subject.foobar(1).should == :return_value
37
42
  end
38
43
  end
39
44
 
@@ -52,7 +57,7 @@ module RR
52
57
  end
53
58
 
54
59
  it "sets return value when block passed in" do
55
- object.foobar(:anything).should == :return_value
60
+ subject.foobar(:anything).should == :return_value
56
61
  end
57
62
  end
58
63
 
@@ -70,7 +75,7 @@ module RR
70
75
  end
71
76
 
72
77
  it "sets return value when block passed in" do
73
- object.foobar().should == :return_value
78
+ subject.foobar().should == :return_value
74
79
  end
75
80
  end
76
81
 
@@ -103,7 +108,7 @@ module RR
103
108
 
104
109
  it "sets return value when block passed in" do
105
110
  double.with_any_args.once {:return_value}
106
- object.foobar.should == :return_value
111
+ subject.foobar.should == :return_value
107
112
  end
108
113
  end
109
114
 
@@ -121,7 +126,7 @@ module RR
121
126
 
122
127
  it "sets return value when block passed in" do
123
128
  double.with_any_args.twice {:return_value}
124
- object.foobar.should == :return_value
129
+ subject.foobar.should == :return_value
125
130
  end
126
131
  end
127
132
 
@@ -137,7 +142,7 @@ module RR
137
142
 
138
143
  it "sets return value when block passed in" do
139
144
  double.with_any_args.at_least(2) {:return_value}
140
- object.foobar.should == :return_value
145
+ subject.foobar.should == :return_value
141
146
  end
142
147
  end
143
148
 
@@ -160,7 +165,7 @@ module RR
160
165
 
161
166
  it "sets return value when block passed in" do
162
167
  double.with_any_args.at_most(2) {:return_value}
163
- object.foobar.should == :return_value
168
+ subject.foobar.should == :return_value
164
169
  end
165
170
  end
166
171
 
@@ -179,7 +184,7 @@ module RR
179
184
 
180
185
  it "sets return value when block passed in" do
181
186
  double.with_any_args.times(3) {:return_value}
182
- object.foobar.should == :return_value
187
+ subject.foobar.should == :return_value
183
188
  end
184
189
  end
185
190
 
@@ -195,7 +200,7 @@ module RR
195
200
 
196
201
  it "sets return value when block passed in" do
197
202
  double.with_any_args.any_number_of_times {:return_value}
198
- object.foobar.should == :return_value
203
+ subject.foobar.should == :return_value
199
204
  end
200
205
  end
201
206
 
@@ -218,7 +223,7 @@ module RR
218
223
 
219
224
  it "sets return value when block passed in" do
220
225
  double.with_any_args.once.ordered {:return_value}
221
- object.foobar.should == :return_value
226
+ subject.foobar.should == :return_value
222
227
  end
223
228
  end
224
229
 
@@ -227,7 +232,7 @@ module RR
227
232
  double.should_not be_ordered
228
233
  end
229
234
  end
230
-
235
+
231
236
  describe "#yields" do
232
237
  it "returns DoubleDefinition" do
233
238
  double.yields(:baz).should === double.definition
@@ -236,7 +241,7 @@ module RR
236
241
  it "yields the passed in argument to the call block when there is no returns value set" do
237
242
  double.with_any_args.yields(:baz)
238
243
  passed_in_block_arg = nil
239
- object.foobar {|arg| passed_in_block_arg = arg}.should == nil
244
+ subject.foobar {|arg| passed_in_block_arg = arg}.should == nil
240
245
  passed_in_block_arg.should == :baz
241
246
  end
242
247
 
@@ -244,13 +249,13 @@ module RR
244
249
  double.with_any_args.yields(:baz).returns(:return_value)
245
250
 
246
251
  passed_in_block_arg = nil
247
- object.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
252
+ subject.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
248
253
  passed_in_block_arg.should == :baz
249
254
  end
250
255
 
251
256
  it "sets return value when block passed in" do
252
257
  double.with_any_args.yields {:return_value}
253
- object.foobar {}.should == :return_value
258
+ subject.foobar {}.should == :return_value
254
259
  end
255
260
  end
256
261
 
@@ -274,11 +279,11 @@ module RR
274
279
  it "receives the return value in the after_call callback" do
275
280
  return_value = :returns_value
276
281
  double.returns(return_value).after_call do |value|
277
- :after_call_value
282
+ :after_call_proc
278
283
  end
279
284
 
280
285
  actual_value = double.call(double_injection)
281
- actual_value.should == :after_call_value
286
+ actual_value.should == :after_call_proc
282
287
  end
283
288
 
284
289
  it "allows after_call to mock the return value" do
@@ -288,7 +293,7 @@ module RR
288
293
  value
289
294
  end
290
295
 
291
- object.foobar.inner_method(1).should == :baz
296
+ subject.foobar.inner_method(1).should == :baz
292
297
  end
293
298
 
294
299
  it "raises an error when not passed a block" do
@@ -312,7 +317,7 @@ module RR
312
317
  it "sets return value when block passed in" do
313
318
  (class << double; self; end).__send__(:define_method, :puts) {|value|}
314
319
  double.with().verbose {:return_value}
315
- object.foobar.should == :return_value
320
+ subject.foobar.should == :return_value
316
321
  end
317
322
  end
318
323
 
@@ -322,25 +327,81 @@ module RR
322
327
  double.returns(:baz).should === double.definition
323
328
  end
324
329
 
325
- it "sets the value of the method when passed a block" do
326
- double.returns {:baz}
327
- double.call(double_injection).should == :baz
328
- end
330
+ context "when passed a block" do
331
+ context "when the block returns a DoubleDefinition" do
332
+ it "causes #call to return the #subject of the DoubleDefinition" do
333
+ new_subject = Object.new
334
+ double.returns do
335
+ definition = stub(new_subject).foobar
336
+ definition.class.should == DoubleDefinitions::DoubleDefinition
337
+ definition
338
+ end
339
+ double.call(double_injection).should == new_subject
340
+ end
341
+ end
329
342
 
330
- it "sets the value of the method when passed an argument" do
331
- double.returns(:baz)
332
- double.call(double_injection).should == :baz
343
+ context "when the block returns a DoubleDefinitionCreatorProxy" do
344
+ it "causes #call to return the #subject of the DoubleDefinition" do
345
+ new_subject = Object.new
346
+ double.returns do
347
+ stub(new_subject)
348
+ end
349
+ double.call(double_injection).should == new_subject
350
+ end
351
+ end
352
+
353
+ context "when the block returns an Object" do
354
+ it "causes #call to return the value of the block" do
355
+ double.returns {:baz}
356
+ double.call(double_injection).should == :baz
357
+ end
358
+ end
333
359
  end
334
360
 
335
- it "returns false when passed false" do
336
- double.returns(false)
337
- double.call(double_injection).should == false
361
+ context "when passed a return value argument" do
362
+ context "when passed a DoubleDefinition" do
363
+ it "causes #call to return the #subject of the DoubleDefinition" do
364
+ new_subject = Object.new
365
+ definition = stub(new_subject).foobar
366
+ definition.class.should == DoubleDefinitions::DoubleDefinition
367
+
368
+ double.returns(definition)
369
+ double.call(double_injection).should == new_subject
370
+ end
371
+ end
372
+
373
+ context "when passed a DoubleDefinitionCreatorProxy" do
374
+ it "causes #call to return the #subject of the DoubleDefinition" do
375
+ new_subject = Object.new
376
+ proxy = stub(new_subject)
377
+ proxy.__creator__.subject.should == new_subject
378
+
379
+ double.returns(proxy)
380
+ double.call(double_injection).should == new_subject
381
+ end
382
+ end
383
+
384
+ context "when passed an Object" do
385
+ it "causes #call to return the Object" do
386
+ double.returns(:baz)
387
+ double.call(double_injection).should == :baz
388
+ end
389
+ end
390
+
391
+ context "when passed false" do
392
+ it "causes #call to return false" do
393
+ double.returns(false)
394
+ double.call(double_injection).should == false
395
+ end
396
+ end
338
397
  end
339
398
 
340
- it "raises an error when both argument and block is passed in" do
341
- lambda do
342
- double.returns(:baz) {:another}
343
- end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
399
+ context "when passed both a return value argument and a block" do
400
+ it "raises an error" do
401
+ lambda do
402
+ double.returns(:baz) {:another}
403
+ end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
404
+ end
344
405
  end
345
406
  end
346
407
 
@@ -349,71 +410,20 @@ module RR
349
410
  double.implemented_by(lambda{:baz}).should === double.definition
350
411
  end
351
412
 
352
- it "sets the implementation to the passed in lambda" do
413
+ it "sets the implementation to the passed in Proc" do
353
414
  double.implemented_by(lambda{:baz})
354
415
  double.call(double_injection).should == :baz
355
416
  end
356
417
 
357
418
  it "sets the implementation to the passed in method" do
358
- def object.foobar(a, b)
419
+ def subject.foobar(a, b)
359
420
  [b, a]
360
421
  end
361
- double.implemented_by(object.method(:foobar))
422
+ double.implemented_by(subject.method(:foobar))
362
423
  double.call(double_injection, 1, 2).should == [2, 1]
363
424
  end
364
425
  end
365
426
 
366
- describe "#proxy" do
367
- it "returns the DoubleDefinition object" do
368
- double.proxy.should === double.definition
369
- end
370
-
371
- it "sets the implementation to the original method" do
372
- double.proxy
373
- double.call(double_injection, 1, 2).should == [2, 1]
374
- end
375
-
376
- it "calls methods when respond_to? is true and methods does not contain original method" do
377
- method_name = nil
378
- class << object
379
- def methods
380
- []
381
- end
382
- def method(name)
383
- raise "We should not be here"
384
- end
385
- def respond_to?(name)
386
- true
387
- end
388
- def method_missing(method_name, *args, &block)
389
- raise "We should not be here"
390
- end
391
- end
392
-
393
- double_injection = space.double_injection(object, :foobar)
394
- double = Double.new(double_injection)
395
- double.with_any_args
396
- double.proxy
397
-
398
- object.foobar(1, 2).should == [2, 1]
399
- end
400
-
401
- it "calls method when original_method does not exist" do
402
- class << object
403
- def method_missing(method_name, *args, &block)
404
- "method_missing for #{method_name}(#{args.inspect})"
405
- end
406
- end
407
- double_injection = space.double_injection(object, :does_not_exist)
408
- double = Double.new(double_injection)
409
- double.with_any_args
410
- double.proxy
411
-
412
- return_value = object.does_not_exist(1, 2)
413
- return_value.should == "method_missing for does_not_exist([1, 2])"
414
- end
415
- end
416
-
417
427
  describe "#call" do
418
428
  describe "when verbose" do
419
429
  it "prints the message call" do
@@ -470,13 +480,13 @@ module RR
470
480
 
471
481
  it "raises DoubleOrderError when ordered and called out of order" do
472
482
  double1 = double
473
- double2 = Double.new(double_injection)
483
+ double2 = Double.new(double_injection, DoubleDefinitions::DoubleDefinition.new(definition_creator, subject))
474
484
 
475
- double1.with(1).returns {:return_1}.ordered.once
476
- double2.with(2).returns {:return_2}.ordered.once
485
+ double1.with(1).returns {:return_1}.once.ordered
486
+ double2.with(2).returns {:return_2}.once.ordered
477
487
 
478
488
  lambda do
479
- object.foobar(2)
489
+ subject.foobar(2)
480
490
  end.should raise_error(
481
491
  Errors::DoubleOrderError,
482
492
  "foobar(2) called out of order in list\n" <<
@@ -519,14 +529,14 @@ module RR
519
529
  it "does not add block argument if no block passed in" do
520
530
  double.with(1, 2).returns {|*args| args}
521
531
 
522
- args = object.foobar(1, 2)
532
+ args = subject.foobar(1, 2)
523
533
  args.should == [1, 2]
524
534
  end
525
535
 
526
536
  it "makes the block the last argument" do
527
537
  double.with(1, 2).returns {|a, b, blk| blk}
528
538
 
529
- block = object.foobar(1, 2) {|a, b| [b, a]}
539
+ block = subject.foobar(1, 2) {|a, b| [b, a]}
530
540
  block.call(3, 4).should == [4, 3]
531
541
  end
532
542
 
@@ -534,71 +544,81 @@ module RR
534
544
  double.with(1, 2).yields(55)
535
545
 
536
546
  lambda do
537
- object.foobar(1, 2)
547
+ subject.foobar(1, 2)
538
548
  end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
539
549
  end
540
550
  end
541
551
 
542
552
  describe "when implemented by a method" do
543
553
  it "sends block to the method" do
544
- def object.foobar(a, b)
554
+ def subject.foobar(a, b)
545
555
  yield(a, b)
546
556
  end
547
557
 
548
- double.with(1, 2).implemented_by(object.method(:foobar))
558
+ double.with(1, 2).implemented_by(subject.method(:foobar))
549
559
 
550
- object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
560
+ subject.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
551
561
  end
552
562
  end
553
563
  end
554
564
 
555
565
  describe "#exact_match?" do
556
- it "returns false when no expectation set" do
557
- double.should_not be_exact_match()
558
- double.should_not be_exact_match(nil)
559
- double.should_not be_exact_match(Object.new)
560
- double.should_not be_exact_match(1, 2, 3)
566
+ context "when no expectation is set" do
567
+ it "raises a DoubleDefinitionError" do
568
+ lambda do
569
+ double.exact_match?
570
+ end.should raise_error(Errors::DoubleDefinitionError)
571
+ end
561
572
  end
562
573
 
563
- it "returns false when arguments are not an exact match" do
564
- double.with(1, 2, 3)
565
- double.should_not be_exact_match(1, 2)
566
- double.should_not be_exact_match(1)
567
- double.should_not be_exact_match()
568
- double.should_not be_exact_match("does not match")
574
+ context "when arguments are not an exact match" do
575
+ it "returns false" do
576
+ double.with(1, 2, 3)
577
+ double.should_not be_exact_match(1, 2)
578
+ double.should_not be_exact_match(1)
579
+ double.should_not be_exact_match()
580
+ double.should_not be_exact_match("does not match")
581
+ end
569
582
  end
570
583
 
571
- it "returns true when arguments are an exact match" do
572
- double.with(1, 2, 3)
573
- double.should be_exact_match(1, 2, 3)
584
+ context "when arguments are an exact match" do
585
+ it "returns true" do
586
+ double.with(1, 2, 3)
587
+ double.should be_exact_match(1, 2, 3)
588
+ end
574
589
  end
575
590
  end
576
591
 
577
592
  describe "#wildcard_match?" do
578
- it "returns false when no expectation set" do
579
- double.should_not be_wildcard_match()
580
- double.should_not be_wildcard_match(nil)
581
- double.should_not be_wildcard_match(Object.new)
582
- double.should_not be_wildcard_match(1, 2, 3)
593
+ context "when no expectation set" do
594
+ it "raises a DoubleDefinitionError" do
595
+ lambda do
596
+ double.wildcard_match?
597
+ end.should raise_error(Errors::DoubleDefinitionError)
598
+ end
583
599
  end
584
600
 
585
- it "returns true when arguments are an exact match" do
586
- double.with(1, 2, 3)
587
- double.should be_wildcard_match(1, 2, 3)
588
- double.should_not be_wildcard_match(1, 2)
589
- double.should_not be_wildcard_match(1)
590
- double.should_not be_wildcard_match()
591
- double.should_not be_wildcard_match("does not match")
601
+ context "when arguments are an exact match" do
602
+ it "returns true" do
603
+ double.with(1, 2, 3)
604
+ double.should be_wildcard_match(1, 2, 3)
605
+ double.should_not be_wildcard_match(1, 2)
606
+ double.should_not be_wildcard_match(1)
607
+ double.should_not be_wildcard_match()
608
+ double.should_not be_wildcard_match("does not match")
609
+ end
592
610
  end
593
611
 
594
- it "returns true when with_any_args" do
595
- double.with_any_args
612
+ context "when with_any_args" do
613
+ it "returns true" do
614
+ double.with_any_args
596
615
 
597
- double.should be_wildcard_match(1, 2, 3)
598
- double.should be_wildcard_match(1, 2)
599
- double.should be_wildcard_match(1)
600
- double.should be_wildcard_match()
601
- double.should be_wildcard_match("does not match")
616
+ double.should be_wildcard_match(1, 2, 3)
617
+ double.should be_wildcard_match(1, 2)
618
+ double.should be_wildcard_match(1)
619
+ double.should be_wildcard_match()
620
+ double.should be_wildcard_match("does not match")
621
+ end
602
622
  end
603
623
  end
604
624