rr 0.4.10 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,4 +1,4 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
2
 
3
3
  module RR
4
4
  module Adapters
@@ -1,363 +1,147 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
2
 
3
3
  module RR
4
4
  module Adapters
5
5
  describe RRMethods do
6
- describe "#mock" do
7
- it_should_behave_like "RR::Adapters::RRMethods"
8
-
9
- before do
10
- @subject = Object.new
11
- class << @subject
12
- def foobar(*args)
13
- :original_value
14
- end
15
- end
16
- end
17
-
18
- it "returns a DoubleDefinitionCreator when passed no arguments" do
19
- mock.should be_instance_of(DoubleDefinitionCreator)
20
- end
21
-
22
- it "sets up the RR mock call chain" do
23
- creates_mock_call_chain(mock(@subject))
24
- end
25
-
26
- it "#rr_mock sets up the RR mock call chain" do
27
- creates_mock_call_chain(rr_mock(@subject))
28
- end
29
-
30
- it "creates a mock Double for method when passed a second argument" do
31
- creates_double_with_method_name(mock(@subject, :foobar))
32
- end
33
-
34
- it "creates a mock Double for method when passed a second argument with rr_mock" do
35
- creates_double_with_method_name(rr_mock(@subject, :foobar))
36
- end
37
-
38
- it "raises error if passed a method name and a block" do
39
- lambda do
40
- mock(@object, :foobar) {}
41
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
42
- end
6
+ attr_reader :subject
7
+ before(:each) do
8
+ @subject = Object.new
9
+ end
43
10
 
44
- def creates_double_with_method_name(double)
45
- double.with(1, 2) {:baz}
46
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
47
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
48
- double.argument_expectation.expected_arguments.should == [1, 2]
11
+ after(:each) do
12
+ RR.reset
13
+ end
49
14
 
50
- @subject.foobar(1, 2).should == :baz
15
+ describe "normal strategy definitions" do
16
+ attr_reader :strategy_method_name
17
+ def call_strategy(*args, &block)
18
+ __send__(strategy_method_name, *args, &block)
51
19
  end
52
20
 
53
- def creates_mock_call_chain(creator)
54
- double = creator.foobar(1, 2) {:baz}
55
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
56
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
57
- double.argument_expectation.expected_arguments.should == [1, 2]
58
-
59
- @subject.foobar(1, 2).should == :baz
60
- end
61
- end
21
+ describe "#mock" do
22
+ before do
23
+ @strategy_method_name = :mock
24
+ end
62
25
 
63
- describe "#stub" do
64
- it_should_behave_like "RR::Adapters::RRMethods"
26
+ send("normal strategy definition")
65
27
 
66
- before do
67
- @subject = Object.new
68
- class << @subject
69
- def foobar(*args)
70
- :original_value
28
+ context "when passing no args" do
29
+ it "returns a DoubleDefinitionCreator" do
30
+ call_strategy.class.should == DoubleDefinitions::DoubleDefinitionCreator
71
31
  end
72
32
  end
73
- end
74
33
 
75
- it "returns a DoubleDefinitionCreator when passed no arguments" do
76
- stub.should be_instance_of(DoubleDefinitionCreator)
77
- end
78
-
79
- it "sets up the RR stub call chain" do
80
- creates_stub_call_chain(stub(@subject))
81
- end
82
-
83
- it "#rr_stub sets up the RR stub call chain" do
84
- creates_stub_call_chain(rr_stub(@subject))
85
- end
86
-
87
- it "creates a stub Double for method when passed a second argument" do
88
- creates_double_with_method_name(stub(@subject, :foobar))
89
- end
90
-
91
- it "#rr_stub creates a stub Double for method when passed a second argument" do
92
- creates_double_with_method_name(rr_stub(@subject, :foobar))
93
- end
94
-
95
- it "raises error if passed a method name and a block" do
96
- lambda do
97
- stub(@object, :foobar) {}
98
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
99
- end
100
-
101
- def creates_double_with_method_name(double)
102
- double.with(1, 2) {:baz}
103
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
104
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
105
- @subject.foobar(1, 2).should == :baz
106
- end
107
-
108
- def creates_stub_call_chain(creator)
109
- double = creator.foobar(1, 2) {:baz}
110
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
111
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
112
- @subject.foobar(1, 2).should == :baz
113
- end
114
- end
115
-
116
- describe "#proxy and #mock" do
117
- it_should_behave_like "RR::Adapters::RRMethods"
118
-
119
- before do
120
- @subject = Object.new
121
- class << @subject
122
- def foobar(*args)
123
- :original_value
34
+ context "when passed a method_name argument" do
35
+ it "creates a mock Double for method" do
36
+ double_definition = mock(subject, :foobar).returns {:baz}
37
+ double_definition.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
38
+ double_definition.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
39
+ double_definition.argument_expectation.expected_arguments.should == []
40
+ subject.foobar.should == :baz
124
41
  end
125
42
  end
126
43
  end
127
44
 
128
- it "#proxy returns a DoubleDefinitionCreator when passed no arguments" do
129
- proxy.should be_instance_of(DoubleDefinitionCreator)
130
- end
131
-
132
- it "#proxy sets up the RR proxy call chain" do
133
- creates_mock_proxy_call_chain(mock.proxy(@subject))
134
- end
135
-
136
- it "#rr_proxy sets up the RR proxy call chain" do
137
- creates_mock_proxy_call_chain(rr_mock.proxy(@subject))
138
- end
139
-
140
- it "#mock_proxy sets up the RR proxy call chain" do
141
- creates_mock_proxy_call_chain(mock.proxy(@subject))
142
- end
143
-
144
- it "#rr_mock_proxy sets up the RR proxy call chain with rr_proxy" do
145
- creates_mock_proxy_call_chain(rr_mock.proxy(@subject))
146
- end
147
-
148
- it "#proxy creates a mock Double for method when passed a second argument" do
149
- creates_double_with_method_name(mock.proxy(@subject, :foobar))
150
- end
151
-
152
- it "#rr_proxy creates a mock Double for method when passed a second argument with rr_mock" do
153
- creates_double_with_method_name(rr_proxy.mock(@subject, :foobar))
154
- end
155
-
156
- it "#mock_proxy creates a mock Double for method when passed a second argument" do
157
- creates_double_with_method_name(mock.proxy(@subject, :foobar))
158
- end
159
-
160
- it "#rr_mock_proxy creates a mock Double for method when passed a second argument with rr_mock" do
161
- creates_double_with_method_name(rr_mock.proxy(@subject, :foobar))
162
- end
163
-
164
- it "raises error if passed a method name and a block" do
165
- lambda do
166
- mock.proxy(@object, :foobar) {}
167
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
168
- end
169
-
170
- def creates_double_with_method_name(double)
171
- double.with(1, 2)
172
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
173
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
174
- double.argument_expectation.expected_arguments.should == [1, 2]
175
-
176
- @subject.foobar(1, 2).should == :original_value
177
- end
178
-
179
- def creates_mock_proxy_call_chain(creator)
180
- double = creator.foobar(1, 2)
181
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
182
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
183
- double.argument_expectation.expected_arguments.should == [1, 2]
184
-
185
- @subject.foobar(1, 2).should == :original_value
186
- end
187
- end
45
+ describe "#stub" do
46
+ before do
47
+ @strategy_method_name = :stub
48
+ end
188
49
 
189
- describe "#stub and #proxy" do
190
- it_should_behave_like "RR::Adapters::RRMethods"
50
+ send("normal strategy definition")
191
51
 
192
- before do
193
- @subject = Object.new
194
- class << @subject
195
- def foobar(*args)
196
- :original_value
52
+ context "when passing no args" do
53
+ it "returns a DoubleDefinitionCreator" do
54
+ call_strategy.class.should == DoubleDefinitions::DoubleDefinitionCreator
197
55
  end
198
56
  end
199
- end
200
-
201
- it "returns a DoubleDefinitionCreator when passed no arguments" do
202
- stub.proxy.should be_instance_of(DoubleDefinitionCreator)
203
- end
204
-
205
- it "sets up the RR proxy call chain" do
206
- creates_stub_proxy_call_chain(stub.proxy(@subject))
207
- end
208
-
209
- it "sets up the RR proxy call chain" do
210
- creates_stub_proxy_call_chain(rr_stub.proxy(@subject))
211
- end
212
-
213
- it "#stub.proxy creates a stub Double for method when passed a second argument" do
214
- creates_double_with_method_name(stub.proxy(@subject, :foobar))
215
- end
216
-
217
- it "#rr_stub.proxy creates a stub Double for method when passed a second argument with rr_stub" do
218
- creates_double_with_method_name(rr_stub.proxy(@subject, :foobar))
219
- end
220
-
221
- it "raises error if passed a method name and a block" do
222
- lambda do
223
- stub.proxy(@object, :foobar) {}
224
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
225
- end
226
-
227
- def creates_double_with_method_name(double)
228
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
229
- double.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
230
-
231
- @subject.foobar(:something).should == :original_value
232
- end
233
-
234
- def creates_stub_proxy_call_chain(creator)
235
- double = creator.foobar
236
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
237
- double.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
238
-
239
- @subject.foobar(1, 2).should == :original_value
240
- end
241
- end
242
57
 
243
- describe "#do_not_allow" do
244
- it_should_behave_like "RR::Adapters::RRMethods"
245
-
246
- before do
247
- @subject = Object.new
248
- class << @subject
249
- def foobar(*args)
250
- :original_value
58
+ context "when passed a method_name argument" do
59
+ it "creates a stub Double for method when passed a method_name argument" do
60
+ double_definition = stub(subject, :foobar).returns {:baz}
61
+ double_definition.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
62
+ double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
63
+ subject.foobar.should == :baz
251
64
  end
252
65
  end
253
66
  end
254
67
 
255
- it "returns a DoubleDefinitionCreator when passed no arguments" do
256
- do_not_allow.should be_instance_of(DoubleDefinitionCreator)
257
- end
258
-
259
- it "sets up the RR do_not_allow call chain" do
260
- creates_do_not_allow_call_chain(dont_allow(@subject))
261
- creates_do_not_allow_call_chain(rr_dont_allow(@subject))
262
- creates_do_not_allow_call_chain(dont_call(@subject))
263
- creates_do_not_allow_call_chain(rr_dont_call(@subject))
264
- creates_do_not_allow_call_chain(do_not_allow(@subject))
265
- creates_do_not_allow_call_chain(rr_do_not_allow(@subject))
266
- creates_do_not_allow_call_chain(dont_allow(@subject))
267
- creates_do_not_allow_call_chain(rr_dont_allow(@subject))
268
- end
269
-
270
- it "creates a mock Double for method when passed a second argument" do
271
- creates_double_with_method_name(dont_allow(@subject, :foobar))
272
- creates_double_with_method_name(rr_dont_allow(@subject, :foobar))
273
- creates_double_with_method_name(dont_call(@subject, :foobar))
274
- creates_double_with_method_name(rr_dont_call(@subject, :foobar))
275
- creates_double_with_method_name(do_not_allow(@subject, :foobar))
276
- creates_double_with_method_name(rr_do_not_allow(@subject, :foobar))
277
- creates_double_with_method_name(dont_allow(@subject, :foobar))
278
- creates_double_with_method_name(rr_dont_allow(@subject, :foobar))
279
- end
280
-
281
- it "raises error if passed a method name and a block" do
282
- lambda do
283
- do_not_allow(@object, :foobar) {}
284
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
285
- end
68
+ describe "#dont_allow" do
69
+ before do
70
+ @strategy_method_name = :dont_allow
71
+ end
286
72
 
287
- def creates_double_with_method_name(double)
288
- double.with(1, 2)
289
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
290
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
291
- double.argument_expectation.expected_arguments.should == [1, 2]
73
+ send("normal strategy definition")
292
74
 
293
- lambda do
294
- @subject.foobar(1, 2)
295
- end.should raise_error(Errors::TimesCalledError)
296
- reset
297
- nil
298
- end
75
+ context "when passing no args" do
76
+ it "returns a DoubleDefinitionCreator" do
77
+ call_strategy.class.should == DoubleDefinitions::DoubleDefinitionCreator
78
+ end
79
+ end
299
80
 
300
- def creates_do_not_allow_call_chain(creator)
301
- double = creator.foobar(1, 2)
302
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
303
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
304
- double.argument_expectation.expected_arguments.should == [1, 2]
81
+ context "when passed a method_name argument_expectation" do
82
+ it "creates a mock Double for method" do
83
+ double_definition = dont_allow(subject, :foobar)
84
+ double_definition.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
85
+ double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
305
86
 
306
- lambda do
307
- @subject.foobar(1, 2)
308
- end.should raise_error(Errors::TimesCalledError)
309
- reset
310
- nil
87
+ lambda do
88
+ subject.foobar
89
+ end.should raise_error(Errors::TimesCalledError)
90
+ RR.reset
91
+ end
92
+ end
311
93
  end
312
94
  end
313
95
 
314
- describe DoubleDefinitionCreator, "#instance_of and #mock" do
315
- before do
316
- @klass = Class.new
96
+ describe "! strategy definitions" do
97
+ attr_reader :strategy_method_name
98
+ def call_strategy(*args, &definition_eval_block)
99
+ __send__(strategy_method_name, *args, &definition_eval_block)
317
100
  end
318
101
 
319
- it "returns a DoubleDefinitionCreator when passed no arguments" do
320
- instance_of.instance_of.should be_instance_of(DoubleDefinitionCreator)
321
- end
102
+ describe "#mock!" do
103
+ before do
104
+ @strategy_method_name = :mock!
105
+ end
322
106
 
323
- it "sets up the RR instance_of call chain" do
324
- creates_instance_of_call_chain(instance_of.mock(@klass))
325
- end
107
+ send("! strategy definition")
326
108
 
327
- it "#rr_instance_of sets up the RR instance_of call chain" do
328
- creates_instance_of_call_chain(rr_instance_of.mock(@klass))
109
+ context "when passed a method_name argument" do
110
+ it "sets #verification_strategy to Mock" do
111
+ proxy = mock!(:foobar)
112
+ proxy.double_definition_creator.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::Mock
113
+ end
114
+ end
329
115
  end
330
116
 
331
- it "creates a instance_of Double for method when passed a second argument" do
332
- creates_double_with_method_name(instance_of.mock(@klass, :foobar))
333
- end
117
+ describe "#stub!" do
118
+ before do
119
+ @strategy_method_name = :stub!
120
+ end
334
121
 
335
- it "creates a instance_of Double for method when passed a second argument with rr_instance_of" do
336
- creates_double_with_method_name(rr_instance_of.mock(@klass, :foobar))
337
- end
122
+ send("! strategy definition")
338
123
 
339
- it "raises error if passed a method name and a block" do
340
- lambda do
341
- instance_of.mock(@klass, :foobar) {}
342
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
124
+ context "when passed a method_name argument" do
125
+ it "sets #verification_strategy to Stub" do
126
+ proxy = stub!(:foobar)
127
+ proxy.double_definition_creator.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::Stub
128
+ end
129
+ end
343
130
  end
344
131
 
345
- def creates_double_with_method_name(double)
346
- double.with(1, 2) {:baz}
347
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
348
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
349
- double.argument_expectation.expected_arguments.should == [1, 2]
350
-
351
- @klass.new.foobar(1, 2).should == :baz
352
- end
132
+ describe "#dont_allow!" do
133
+ before do
134
+ @strategy_method_name = :dont_allow!
135
+ end
353
136
 
354
- def creates_instance_of_call_chain(creator)
355
- double = creator.foobar(1, 2) {:baz}
356
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
357
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
358
- double.argument_expectation.expected_arguments.should == [1, 2]
137
+ send("! strategy definition")
359
138
 
360
- @klass.new.foobar(1, 2).should == :baz
139
+ context "when passed a method_name argument" do
140
+ it "sets #verification_strategy to DontAllow" do
141
+ proxy = dont_allow!(:foobar)
142
+ proxy.double_definition_creator.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::DontAllow
143
+ end
144
+ end
361
145
  end
362
146
  end
363
147
  end