jferris-rr 0.7.1.0.1239654108

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/CHANGES +196 -0
  2. data/README.rdoc +329 -0
  3. data/Rakefile +77 -0
  4. data/lib/rr.rb +84 -0
  5. data/lib/rr/adapters/rr_methods.rb +122 -0
  6. data/lib/rr/adapters/rspec.rb +58 -0
  7. data/lib/rr/adapters/test_unit.rb +29 -0
  8. data/lib/rr/double.rb +212 -0
  9. data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
  10. data/lib/rr/double_definitions/double_definition.rb +346 -0
  11. data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
  12. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
  13. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  14. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  15. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  16. data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
  17. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  18. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +46 -0
  19. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  20. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  21. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  22. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  23. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  24. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  25. data/lib/rr/double_injection.rb +143 -0
  26. data/lib/rr/double_matches.rb +51 -0
  27. data/lib/rr/errors/argument_equality_error.rb +6 -0
  28. data/lib/rr/errors/double_definition_error.rb +6 -0
  29. data/lib/rr/errors/double_not_found_error.rb +6 -0
  30. data/lib/rr/errors/double_order_error.rb +6 -0
  31. data/lib/rr/errors/rr_error.rb +20 -0
  32. data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
  33. data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
  34. data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
  35. data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
  36. data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
  37. data/lib/rr/errors/times_called_error.rb +6 -0
  38. data/lib/rr/expectations/any_argument_expectation.rb +21 -0
  39. data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
  40. data/lib/rr/expectations/times_called_expectation.rb +57 -0
  41. data/lib/rr/hash_with_object_id_key.rb +41 -0
  42. data/lib/rr/recorded_calls.rb +103 -0
  43. data/lib/rr/space.rb +123 -0
  44. data/lib/rr/spy_verification.rb +48 -0
  45. data/lib/rr/spy_verification_proxy.rb +18 -0
  46. data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
  47. data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
  48. data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
  49. data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
  50. data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
  51. data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
  52. data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
  53. data/lib/rr/times_called_matchers/terminal.rb +20 -0
  54. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  55. data/lib/rr/wildcard_matchers/anything.rb +18 -0
  56. data/lib/rr/wildcard_matchers/boolean.rb +23 -0
  57. data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
  58. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  59. data/lib/rr/wildcard_matchers/is_a.rb +25 -0
  60. data/lib/rr/wildcard_matchers/numeric.rb +13 -0
  61. data/lib/rr/wildcard_matchers/range.rb +7 -0
  62. data/lib/rr/wildcard_matchers/regexp.rb +7 -0
  63. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  64. data/spec/core_spec_suite.rb +19 -0
  65. data/spec/environment_fixture_setup.rb +6 -0
  66. data/spec/high_level_spec.rb +368 -0
  67. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  68. data/spec/rr/adapters/rr_methods_creator_spec.rb +149 -0
  69. data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
  70. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  71. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
  72. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
  73. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
  74. data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
  75. data/spec/rr/double_definitions/double_definition_spec.rb +1159 -0
  76. data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
  77. data/spec/rr/double_injection/double_injection_dispatching_spec.rb +244 -0
  78. data/spec/rr/double_injection/double_injection_has_original_method_spec.rb +55 -0
  79. data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
  80. data/spec/rr/double_injection/double_injection_spec.rb +77 -0
  81. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  82. data/spec/rr/double_spec.rb +352 -0
  83. data/spec/rr/errors/rr_error_spec.rb +67 -0
  84. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  85. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  86. data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
  87. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
  88. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  89. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  90. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  91. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  92. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +46 -0
  93. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
  94. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  95. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
  96. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
  97. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
  98. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
  99. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
  100. data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
  101. data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
  102. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -0
  103. data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
  104. data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
  105. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  106. data/spec/rr/space/space_spec.rb +542 -0
  107. data/spec/rr/test_unit/test_helper.rb +7 -0
  108. data/spec/rr/test_unit/test_unit_backtrace_test.rb +35 -0
  109. data/spec/rr/test_unit/test_unit_integration_test.rb +57 -0
  110. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  111. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  112. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  113. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  114. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  115. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  116. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  117. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  118. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  119. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  120. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  121. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  122. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  123. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  124. data/spec/rr_spec.rb +28 -0
  125. data/spec/rspec_spec_suite.rb +16 -0
  126. data/spec/spec_helper.rb +107 -0
  127. data/spec/spec_suite.rb +27 -0
  128. data/spec/spy_verification_spec.rb +129 -0
  129. data/spec/test_unit_spec_suite.rb +21 -0
  130. metadata +187 -0
@@ -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.definition.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
@@ -0,0 +1,352 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module RR
4
+ describe Double do
5
+ it_should_behave_like "Swapped Space"
6
+ attr_reader :subject, :double_injection, :definition, :definition_creator, :double
7
+ before do
8
+ @subject = Object.new
9
+ def subject.foobar(a, b)
10
+ [b, a]
11
+ end
12
+ @double_injection = create_double_injection
13
+ @definition_creator = DoubleDefinitions::DoubleDefinitionCreator.new
14
+ @definition = DoubleDefinitions::DoubleDefinition.new(definition_creator, subject).
15
+ any_number_of_times.
16
+ with_any_args
17
+ @double = Double.new(double_injection, definition)
18
+ end
19
+
20
+ def create_double_injection
21
+ space.double_injection(subject, :foobar)
22
+ end
23
+
24
+ describe "#initialize" do
25
+ it "registers self with associated DoubleInjection" do
26
+ double_injection.doubles.should include(double)
27
+ end
28
+ end
29
+
30
+ describe "#ordered?" do
31
+ it "defaults to false" do
32
+ double.should_not be_ordered
33
+ end
34
+ end
35
+
36
+ describe "#call" do
37
+ describe "when verbose" do
38
+ it "prints the message call" do
39
+ double.definition.verbose
40
+ output = nil
41
+ (class << double; self; end).__send__(:define_method, :puts) do |output|
42
+ output = output
43
+ end
44
+ double.call(double_injection, 1, 2)
45
+ output.should == Double.formatted_name(:foobar, [1, 2])
46
+ end
47
+ end
48
+
49
+ describe "when not verbose" do
50
+ it "does not print the message call" do
51
+ output = nil
52
+ (class << double; self; end).__send__(:define_method, :puts) do |output|
53
+ output = output
54
+ end
55
+ double.call(double_injection, 1, 2)
56
+ output.should be_nil
57
+ end
58
+ end
59
+
60
+ describe "when implemented by a lambda" do
61
+ it "calls the return lambda when implemented by a lambda" do
62
+ double.definition.returns {|arg| "returning #{arg}"}
63
+ double.call(double_injection, :foobar).should == "returning foobar"
64
+ end
65
+
66
+ it "calls and returns the after_call when after_call is set" do
67
+ double.definition.returns {|arg| "returning #{arg}"}.after_call do |value|
68
+ "#{value} after call"
69
+ end
70
+ double.call(double_injection, :foobar).should == "returning foobar after call"
71
+ end
72
+
73
+ it "returns nil when to returns is not set" do
74
+ double.call(double_injection).should be_nil
75
+ end
76
+
77
+ it "works when times_called is not set" do
78
+ double.definition.returns {:value}
79
+ double.call(double_injection)
80
+ end
81
+
82
+ it "verifes the times_called does not exceed the TimesCalledExpectation" do
83
+ double.definition.times(2).returns {:value}
84
+
85
+ double.call(double_injection, :foobar)
86
+ double.call(double_injection, :foobar)
87
+ lambda {double.call(double_injection, :foobar)}.should raise_error(Errors::TimesCalledError)
88
+ end
89
+
90
+ it "raises DoubleOrderError when ordered and called out of order" do
91
+ double1 = double
92
+ double2 = Double.new(double_injection, DoubleDefinitions::DoubleDefinition.new(definition_creator, subject))
93
+
94
+ double1.definition.with(1).returns {:return_1}.once.ordered
95
+ double2.definition.with(2).returns {:return_2}.once.ordered
96
+
97
+ lambda do
98
+ subject.foobar(2)
99
+ end.should raise_error(
100
+ Errors::DoubleOrderError,
101
+ "foobar(2) called out of order in list\n" <<
102
+ "- foobar(1)\n" <<
103
+ "- foobar(2)"
104
+ )
105
+ end
106
+
107
+ it "dispatches to Space#verify_ordered_double when ordered" do
108
+ verify_ordered_double_called = false
109
+ passed_in_double = nil
110
+ space.method(:verify_ordered_double).arity.should == 1
111
+ (class << space; self; end).class_eval do
112
+ define_method :verify_ordered_double do |double|
113
+ passed_in_double = double
114
+ verify_ordered_double_called = true
115
+ end
116
+ end
117
+
118
+ double.definition.returns {:value}.ordered
119
+ double.call(double_injection, :foobar)
120
+ verify_ordered_double_called.should be_true
121
+ passed_in_double.should === double
122
+ end
123
+
124
+ it "does not dispatche to Space#verify_ordered_double when not ordered" do
125
+ verify_ordered_double_called = false
126
+ space.method(:verify_ordered_double).arity.should == 1
127
+ (class << space; self; end).class_eval do
128
+ define_method :verify_ordered_double do |double|
129
+ verify_ordered_double_called = true
130
+ end
131
+ end
132
+
133
+ double.definition.returns {:value}
134
+ double.call(double_injection, :foobar)
135
+ verify_ordered_double_called.should be_false
136
+ end
137
+
138
+ it "does not add block argument if no block passed in" do
139
+ double.definition.with(1, 2).returns {|*args| args}
140
+
141
+ args = subject.foobar(1, 2)
142
+ args.should == [1, 2]
143
+ end
144
+
145
+ it "makes the block the last argument" do
146
+ double.definition.with(1, 2).returns {|a, b, blk| blk}
147
+
148
+ block = subject.foobar(1, 2) {|a, b| [b, a]}
149
+ block.call(3, 4).should == [4, 3]
150
+ end
151
+
152
+ it "raises ArgumentError when yields was called and no block passed in" do
153
+ double.definition.with(1, 2).yields(55)
154
+
155
+ lambda do
156
+ subject.foobar(1, 2)
157
+ end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
158
+ end
159
+ end
160
+
161
+ describe "when implemented by a method" do
162
+ it "sends block to the method" do
163
+ def subject.foobar(a, b)
164
+ yield(a, b)
165
+ end
166
+
167
+ double.definition.with(1, 2).implemented_by(subject.method(:foobar))
168
+
169
+ subject.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
170
+ end
171
+ end
172
+ end
173
+
174
+ describe "#exact_match?" do
175
+ context "when no expectation is set" do
176
+ it "raises a DoubleDefinitionError" do
177
+ double.definition.argument_expectation = nil
178
+ lambda do
179
+ double.exact_match?
180
+ end.should raise_error(Errors::DoubleDefinitionError)
181
+ end
182
+ end
183
+
184
+ context "when arguments are not an exact match" do
185
+ it "returns false" do
186
+ double.definition.with(1, 2, 3)
187
+ double.should_not be_exact_match(1, 2)
188
+ double.should_not be_exact_match(1)
189
+ double.should_not be_exact_match()
190
+ double.should_not be_exact_match("does not match")
191
+ end
192
+ end
193
+
194
+ context "when arguments are an exact match" do
195
+ it "returns true" do
196
+ double.definition.with(1, 2, 3)
197
+ double.should be_exact_match(1, 2, 3)
198
+ end
199
+ end
200
+ end
201
+
202
+ describe "#wildcard_match?" do
203
+ context "when no expectation set" do
204
+ it "raises a DoubleDefinitionError" do
205
+ double.definition.argument_expectation = nil
206
+ lambda do
207
+ double.wildcard_match?
208
+ end.should raise_error(Errors::DoubleDefinitionError)
209
+ end
210
+ end
211
+
212
+ context "when arguments are an exact match" do
213
+ it "returns true" do
214
+ double.definition.with(1, 2, 3)
215
+ double.should be_wildcard_match(1, 2, 3)
216
+ double.should_not be_wildcard_match(1, 2)
217
+ double.should_not be_wildcard_match(1)
218
+ double.should_not be_wildcard_match()
219
+ double.should_not be_wildcard_match("does not match")
220
+ end
221
+ end
222
+
223
+ context "when with_any_args" do
224
+ it "returns true" do
225
+ double.definition.with_any_args
226
+
227
+ double.should be_wildcard_match(1, 2, 3)
228
+ double.should be_wildcard_match(1, 2)
229
+ double.should be_wildcard_match(1)
230
+ double.should be_wildcard_match()
231
+ double.should be_wildcard_match("does not match")
232
+ end
233
+ end
234
+ end
235
+
236
+ describe "#attempt?" do
237
+ context "when TimesCalledExpectation#attempt? is true" do
238
+ it "returns true" do
239
+ double.definition.with(1, 2, 3).twice
240
+ double.call(double_injection, 1, 2, 3)
241
+ double.times_called_expectation.should be_attempt
242
+ double.should be_attempt
243
+ end
244
+ end
245
+
246
+ context "when TimesCalledExpectation#attempt? is true" do
247
+ it "returns false" do
248
+ double.definition.with(1, 2, 3).twice
249
+ double.call(double_injection, 1, 2, 3)
250
+ double.call(double_injection, 1, 2, 3)
251
+ double.times_called_expectation.should_not be_attempt
252
+ double.should_not be_attempt
253
+ end
254
+ end
255
+
256
+ context "when there is no Times Called expectation" do
257
+ it "raises a DoubleDefinitionError" do
258
+ double.definition.with(1, 2, 3)
259
+ double.definition.times_matcher = nil
260
+ lambda do
261
+ double.should be_attempt
262
+ end.should raise_error(RR::Errors::DoubleDefinitionError)
263
+ end
264
+ end
265
+ end
266
+
267
+ describe "#verify" do
268
+ it "verifies that times called expectation was met" do
269
+ double.definition.twice.returns {:return_value}
270
+
271
+ lambda {double.verify}.should raise_error(Errors::TimesCalledError)
272
+ double.call(double_injection)
273
+ lambda {double.verify}.should raise_error(Errors::TimesCalledError)
274
+ double.call(double_injection)
275
+
276
+ lambda {double.verify}.should_not raise_error
277
+ end
278
+
279
+ it "does not raise an error when there is no times called expectation" do
280
+ lambda {double.verify}.should_not raise_error
281
+ double.call(double_injection)
282
+ lambda {double.verify}.should_not raise_error
283
+ double.call(double_injection)
284
+ lambda {double.verify}.should_not raise_error
285
+ end
286
+ end
287
+
288
+ describe "#terminal?" do
289
+ context "when times_called_expectation's terminal? is true" do
290
+ it "returns true" do
291
+ double.definition.once
292
+ double.times_called_expectation.should be_terminal
293
+ double.should be_terminal
294
+ end
295
+ end
296
+
297
+ context "when times_called_expectation's terminal? is false" do
298
+ it "returns false" do
299
+ double.definition.any_number_of_times
300
+ double.times_called_expectation.should_not be_terminal
301
+ double.should_not be_terminal
302
+ end
303
+ end
304
+
305
+ context "when there is no times_matcher" do
306
+ it "raises a DoubleDefinitionError" do
307
+ double.definition.times_matcher = nil
308
+ lambda do
309
+ double.should_not be_terminal
310
+ end.should raise_error(RR::Errors::DoubleDefinitionError)
311
+ end
312
+ end
313
+ end
314
+
315
+ describe "#method_name" do
316
+ it "returns the DoubleInjection's method_name" do
317
+ double_injection.method_name.should == :foobar
318
+ double.method_name.should == :foobar
319
+ end
320
+ end
321
+
322
+ describe "#expected_arguments" do
323
+ context "when there is an argument expectation" do
324
+ it "returns argument expectation's expected_arguments" do
325
+ double.definition.with(1, 2)
326
+ double.definition.argument_expectation.should_not be_nil
327
+ double.expected_arguments.should == [1, 2]
328
+ end
329
+ end
330
+
331
+ context "when there is no argument expectation" do
332
+ it "raises an DoubleDefinitionError" do
333
+ double.definition.argument_expectation = nil
334
+ lambda do
335
+ double.expected_arguments
336
+ end.should raise_error(Errors::DoubleDefinitionError)
337
+ end
338
+ end
339
+ end
340
+
341
+ describe "#formatted_name" do
342
+ it "renders the formatted name of the Double with no arguments" do
343
+ double.formatted_name.should == "foobar()"
344
+ end
345
+
346
+ it "renders the formatted name of the Double with arguments" do
347
+ double.definition.with(1, 2)
348
+ double.formatted_name.should == "foobar(1, 2)"
349
+ end
350
+ end
351
+ end
352
+ end