rr 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/{README → README.rdoc} +14 -6
- data/Rakefile +2 -2
- data/lib/rr.rb +11 -3
- data/lib/rr/adapters/rr_methods.rb +12 -12
- data/lib/rr/adapters/rspec.rb +3 -3
- data/lib/rr/adapters/test_unit.rb +3 -3
- data/lib/rr/double.rb +12 -10
- data/lib/rr/double_creator.rb +48 -45
- data/lib/rr/double_definition.rb +17 -149
- data/lib/rr/double_definition_builder.rb +11 -11
- data/lib/rr/double_definition_creator.rb +156 -0
- data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
- data/lib/rr/double_injection.rb +6 -6
- data/lib/rr/double_matches.rb +40 -40
- data/lib/rr/errors/rr_error.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/space.rb +9 -30
- data/spec/high_level_spec.rb +140 -143
- data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
- data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
- data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
- data/spec/rr/double/double_injection_reset_spec.rb +1 -1
- data/spec/rr/double/double_injection_verify_spec.rb +5 -4
- data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
- data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
- data/spec/rr/double_definition_spec.rb +637 -642
- data/spec/rr/double_spec.rb +44 -43
- data/spec/rr/errors/rr_error_spec.rb +6 -6
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
- data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +372 -18
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
- data/spec/spec_helper.rb +14 -3
- data/spec/spec_suite.rb +2 -2
- metadata +47 -45
- data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
- data/spec/rr/space/space_create_spec.rb +0 -268
- data/spec/rr/space/space_helper.rb +0 -7
- data/spec/rr/space/space_register_spec.rb +0 -32
- data/spec/rr/space/space_reset_spec.rb +0 -131
- data/spec/rr/space/space_verify_spec.rb +0 -181
data/CHANGES
CHANGED
data/{README → README.rdoc}
RENAMED
@@ -42,10 +42,10 @@ Here is RR compared to other mock frameworks:
|
|
42
42
|
User.should_receive(:find).with('42') {jane} # Rspec using return value blocks
|
43
43
|
mock(User).find('42') {jane} # RR
|
44
44
|
|
45
|
-
=== No mock
|
45
|
+
=== No "pure" mock object
|
46
46
|
RR is an opinionated framework. RR does not create a mock object for you,
|
47
47
|
like other frameworks. Instead, RR utilizes a technique known as
|
48
|
-
"
|
48
|
+
"double injection".
|
49
49
|
|
50
50
|
my_object = MyClass.new
|
51
51
|
mock(my_object).hello
|
@@ -54,6 +54,10 @@ Compare this with doing a mock in mocha:
|
|
54
54
|
my_mocked_object = mock()
|
55
55
|
my_mocked_object.expects(:hello)
|
56
56
|
|
57
|
+
If you wish to use objects for the sole purpose of being a mock, you can
|
58
|
+
do so by creating an empty object.
|
59
|
+
mock(my_mock_object = Object.new).hello
|
60
|
+
|
57
61
|
=== No should_receive or expects method
|
58
62
|
RR uses method_missing to set your method expectation. This means you do not
|
59
63
|
need to use a method such as should_receive or expects.
|
@@ -186,7 +190,7 @@ Put double scenarios on instances of a Class.
|
|
186
190
|
m.system("rake baz") {true}
|
187
191
|
end
|
188
192
|
|
189
|
-
=== Wildcard matchers
|
193
|
+
=== Argument Wildcard matchers
|
190
194
|
==== anything
|
191
195
|
mock(object).foobar(1, anything)
|
192
196
|
object.foobar(1, :my_symbol)
|
@@ -199,7 +203,7 @@ Put double scenarios on instances of a Class.
|
|
199
203
|
mock(object).foobar(numeric)
|
200
204
|
object.foobar(99)
|
201
205
|
|
202
|
-
====
|
206
|
+
==== boolean
|
203
207
|
mock(object).foobar(boolean)
|
204
208
|
object.foobar(false)
|
205
209
|
|
@@ -210,6 +214,10 @@ Put double scenarios on instances of a Class.
|
|
210
214
|
def arg.talk; 'quack'; end
|
211
215
|
object.foobar(arg)
|
212
216
|
|
217
|
+
=== Invocation Amount Wildcard Matchers
|
218
|
+
==== any_times
|
219
|
+
mock(object).method_name(anything).times(any_times) {return_value}
|
220
|
+
|
213
221
|
== Special Thanks To
|
214
222
|
With any development effort, there are countless people who have contributed
|
215
223
|
to making it possible. We all are standing on the shoulders of giants.
|
@@ -220,9 +228,9 @@ to making it possible. We all are standing on the shoulders of giants.
|
|
220
228
|
* Nick Kallen for documentation suggestion & bug reports
|
221
229
|
* David Chelimsky for encouragement to make the RR framework, for developing
|
222
230
|
the Rspec mock framework, and syntax ideas
|
223
|
-
*
|
231
|
+
* Gerard Meszaros for his excellent book "xUnit Test Patterns"
|
224
232
|
* Dan North for syntax ideas
|
225
|
-
* Jim Weirich for developing Flexmock, the first Terse ruby mock framework
|
233
|
+
* Jim Weirich for developing Flexmock, the first Terse ruby mock framework in Ruby
|
226
234
|
* James Mead for developing Mocha
|
227
235
|
* Aslak Hellesoy for Developing Rspec
|
228
236
|
* Stephen Baker for Developing Rspec
|
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ def run_suite
|
|
26
26
|
end
|
27
27
|
|
28
28
|
PKG_NAME = "rr"
|
29
|
-
PKG_VERSION = "0.4.
|
29
|
+
PKG_VERSION = "0.4.9"
|
30
30
|
PKG_FILES = FileList[
|
31
31
|
'[A-Z]*',
|
32
32
|
'*.rb',
|
@@ -47,7 +47,7 @@ spec = Gem::Specification.new do |s|
|
|
47
47
|
s.require_path = 'lib'
|
48
48
|
|
49
49
|
s.has_rdoc = true
|
50
|
-
s.extra_rdoc_files = [ "README", "CHANGES" ]
|
50
|
+
s.extra_rdoc_files = [ "README.rdoc", "CHANGES" ]
|
51
51
|
s.rdoc_options = ["--main", "README", "--inline-source", "--line-numbers"]
|
52
52
|
|
53
53
|
s.test_files = Dir.glob('spec/*_spec.rb')
|
data/lib/rr.rb
CHANGED
@@ -10,9 +10,9 @@ require "#{dir}/rr/space"
|
|
10
10
|
require "#{dir}/rr/double_injection"
|
11
11
|
require "#{dir}/rr/hash_with_object_id_key"
|
12
12
|
|
13
|
-
require "#{dir}/rr/
|
13
|
+
require "#{dir}/rr/double_definition_creator_proxy"
|
14
14
|
|
15
|
-
require "#{dir}/rr/
|
15
|
+
require "#{dir}/rr/double_definition_creator"
|
16
16
|
|
17
17
|
require "#{dir}/rr/double"
|
18
18
|
require "#{dir}/rr/double_definition"
|
@@ -44,4 +44,12 @@ require "#{dir}/rr/times_called_matchers/at_most_matcher"
|
|
44
44
|
require "#{dir}/rr/adapters/rr_methods"
|
45
45
|
|
46
46
|
require "#{dir}/rr/adapters/rspec"
|
47
|
-
require "#{dir}/rr/adapters/test_unit"
|
47
|
+
require "#{dir}/rr/adapters/test_unit"
|
48
|
+
|
49
|
+
module RR
|
50
|
+
class << self
|
51
|
+
def method_missing(method_name, *args, &block)
|
52
|
+
RR::Space.instance.__send__(method_name, *args, &block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -22,7 +22,7 @@ module RR
|
|
22
22
|
# or
|
23
23
|
# proxy.mock(subject).method_name_1
|
24
24
|
#
|
25
|
-
# When passed the subject, a
|
25
|
+
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
26
26
|
# a method with arguments to the proxy will set up expectations that
|
27
27
|
# the a call to the subject's method with the arguments will happen,
|
28
28
|
# and return the prescribed value.
|
@@ -40,8 +40,8 @@ module RR
|
|
40
40
|
# method_name_1 {return_value_1}
|
41
41
|
# method_name_2(arg_1, arg_2) {return_value_2}
|
42
42
|
# end
|
43
|
-
def mock(subject=
|
44
|
-
creator =
|
43
|
+
def mock(subject=DoubleDefinitionCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
44
|
+
creator = DoubleDefinitionCreator.new
|
45
45
|
creator.mock(subject, method_name, &definition)
|
46
46
|
end
|
47
47
|
|
@@ -56,7 +56,7 @@ module RR
|
|
56
56
|
# or
|
57
57
|
# proxy.stub(subject).method_name_1
|
58
58
|
#
|
59
|
-
# When passed the subject, a
|
59
|
+
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
60
60
|
# a method with arguments to the proxy will set up expectations that
|
61
61
|
# the a call to the subject's method with the arguments will happen,
|
62
62
|
# and return the prescribed value.
|
@@ -74,8 +74,8 @@ module RR
|
|
74
74
|
# method_name_1 {return_value_1}
|
75
75
|
# method_name_2(arg_1, arg_2) {return_value_2}
|
76
76
|
# end
|
77
|
-
def stub(subject=
|
78
|
-
creator =
|
77
|
+
def stub(subject=DoubleDefinitionCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
78
|
+
creator = DoubleDefinitionCreator.new
|
79
79
|
creator.stub(subject, method_name, &definition)
|
80
80
|
end
|
81
81
|
|
@@ -124,8 +124,8 @@ module RR
|
|
124
124
|
# html.should include("My socks are wet")
|
125
125
|
# "My new return value"
|
126
126
|
# end
|
127
|
-
def proxy(subject=
|
128
|
-
creator =
|
127
|
+
def proxy(subject=DoubleDefinitionCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
128
|
+
creator = DoubleDefinitionCreator.new
|
129
129
|
creator.proxy(subject, method_name, &definition)
|
130
130
|
end
|
131
131
|
|
@@ -145,8 +145,8 @@ module RR
|
|
145
145
|
# m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
|
146
146
|
# m.method3.with_no_args # Do not allow method3 with no arguments
|
147
147
|
# end
|
148
|
-
def dont_allow(subject=
|
149
|
-
creator =
|
148
|
+
def dont_allow(subject=DoubleDefinitionCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
149
|
+
creator = DoubleDefinitionCreator.new
|
150
150
|
creator.dont_allow(subject, method_name, &definition)
|
151
151
|
end
|
152
152
|
alias_method :do_not_allow, :dont_allow
|
@@ -164,8 +164,8 @@ module RR
|
|
164
164
|
# mock.instance_of(User).projects do |projects|
|
165
165
|
# projects[0..2]
|
166
166
|
# end
|
167
|
-
def instance_of(subject=
|
168
|
-
creator =
|
167
|
+
def instance_of(subject=DoubleDefinitionCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
168
|
+
creator = DoubleDefinitionCreator.new
|
169
169
|
creator.instance_of(subject, method_name, &definition)
|
170
170
|
end
|
171
171
|
|
data/lib/rr/adapters/rspec.rb
CHANGED
@@ -3,18 +3,18 @@ module RR
|
|
3
3
|
module TestUnit
|
4
4
|
include RRMethods
|
5
5
|
def self.included(mod)
|
6
|
-
RR
|
6
|
+
RR.trim_backtrace = true
|
7
7
|
mod.class_eval do
|
8
8
|
alias_method :setup_without_rr, :setup
|
9
9
|
def setup_with_rr
|
10
10
|
setup_without_rr
|
11
|
-
|
11
|
+
RR.reset
|
12
12
|
end
|
13
13
|
alias_method :setup, :setup_with_rr
|
14
14
|
|
15
15
|
alias_method :teardown_without_rr, :teardown
|
16
16
|
def teardown_with_rr
|
17
|
-
|
17
|
+
RR.verify
|
18
18
|
teardown_without_rr
|
19
19
|
end
|
20
20
|
alias_method :teardown, :teardown_with_rr
|
data/lib/rr/double.rb
CHANGED
@@ -17,13 +17,15 @@ module RR
|
|
17
17
|
end
|
18
18
|
|
19
19
|
attr_reader :times_called, :double_injection, :definition
|
20
|
+
include Space::Reader
|
20
21
|
|
21
|
-
def initialize(
|
22
|
-
@space = space
|
22
|
+
def initialize(double_injection, definition = DoubleDefinition.new)
|
23
23
|
@double_injection = double_injection
|
24
24
|
@definition = definition
|
25
25
|
@times_called = 0
|
26
26
|
@times_called_expectation = Expectations::TimesCalledExpectation.new(self)
|
27
|
+
definition.double = self
|
28
|
+
double_injection.register_double self
|
27
29
|
end
|
28
30
|
|
29
31
|
# Double#with sets the expectation that the Double will receive
|
@@ -193,8 +195,8 @@ module RR
|
|
193
195
|
# the passed in block.
|
194
196
|
#
|
195
197
|
# Passing in an argument causes Double to return the argument.
|
196
|
-
def returns(
|
197
|
-
definition.returns(
|
198
|
+
def returns(*args, &implementation)
|
199
|
+
definition.returns(*args, &implementation)
|
198
200
|
end
|
199
201
|
|
200
202
|
# Double#implemented_by sets the implementation of the Double.
|
@@ -210,7 +212,7 @@ module RR
|
|
210
212
|
definition.implemented_by implementation
|
211
213
|
end
|
212
214
|
|
213
|
-
# Double#
|
215
|
+
# Double#proxy sets the implementation
|
214
216
|
# of the Double to be the original method.
|
215
217
|
# This is primarily used with proxy.
|
216
218
|
#
|
@@ -218,10 +220,10 @@ module RR
|
|
218
220
|
# def obj.foobar
|
219
221
|
# yield(1)
|
220
222
|
# end
|
221
|
-
# mock(obj).method_name.
|
223
|
+
# mock(obj).method_name.proxy
|
222
224
|
# obj.foobar {|arg| puts arg} # puts 1
|
223
|
-
def
|
224
|
-
definition.
|
225
|
+
def proxy
|
226
|
+
definition.proxy
|
225
227
|
end
|
226
228
|
|
227
229
|
# Double#call calls the Double's implementation. The return
|
@@ -233,8 +235,8 @@ module RR
|
|
233
235
|
if verbose?
|
234
236
|
puts Double.formatted_name(double_injection.method_name, args)
|
235
237
|
end
|
236
|
-
self.times_called_expectation.attempt
|
237
|
-
|
238
|
+
self.times_called_expectation.attempt if definition.times_matcher
|
239
|
+
space.verify_ordered_double(self) if ordered?
|
238
240
|
yields!(block)
|
239
241
|
return_value = call_implementation(double_injection, *args, &block)
|
240
242
|
return return_value unless definition.after_call_value
|
data/lib/rr/double_creator.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module RR
|
2
|
-
# RR::
|
2
|
+
# RR::DoubleDefinitionCreator provides a strategies to create a Double.
|
3
3
|
# The strategies are:
|
4
4
|
# * mock
|
5
5
|
# * stub
|
6
6
|
# * proxy
|
7
7
|
# * dont_allow
|
8
|
-
class
|
8
|
+
class DoubleDefinitionCreator
|
9
9
|
NO_SUBJECT_ARG = Object.new
|
10
10
|
|
11
11
|
attr_reader :space
|
@@ -14,9 +14,8 @@ module RR
|
|
14
14
|
def initialize(space)
|
15
15
|
@space = space
|
16
16
|
@strategy = nil
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@instance_of_method_name = nil
|
17
|
+
@using_proxy_strategy = false
|
18
|
+
@instance_of_called = nil
|
20
19
|
end
|
21
20
|
|
22
21
|
# This method sets the Double to have a mock strategy. A mock strategy
|
@@ -29,7 +28,7 @@ module RR
|
|
29
28
|
# or
|
30
29
|
# proxy.mock(subject).method_name_1
|
31
30
|
#
|
32
|
-
# When passed the subject, a
|
31
|
+
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
33
32
|
# a method with arguments to the proxy will set up expectations that
|
34
33
|
# the a call to the subject's method with the arguments will happen.
|
35
34
|
# mock(subject).method_name_1 {return_value_1}
|
@@ -47,10 +46,10 @@ module RR
|
|
47
46
|
# method_name_2(arg_1, arg_2) {return_value_2}
|
48
47
|
# end
|
49
48
|
def mock(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
50
|
-
|
49
|
+
verify_no_strategy
|
51
50
|
@strategy = :mock
|
52
51
|
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
53
|
-
|
52
|
+
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
54
53
|
end
|
55
54
|
|
56
55
|
# This method sets the Double to have a stub strategy. A stub strategy
|
@@ -63,7 +62,7 @@ module RR
|
|
63
62
|
# or
|
64
63
|
# proxy.stub(subject).method_name_1
|
65
64
|
#
|
66
|
-
# When passed the subject, a
|
65
|
+
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
67
66
|
# a method with arguments to the proxy will set up expectations that
|
68
67
|
# the a call to the subject's method with the arguments will happen,
|
69
68
|
# and return the prescribed value.
|
@@ -82,10 +81,10 @@ module RR
|
|
82
81
|
# method_name_2(arg_1, arg_2) {return_value_2}
|
83
82
|
# end
|
84
83
|
def stub(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
85
|
-
|
84
|
+
verify_no_strategy
|
86
85
|
@strategy = :stub
|
87
86
|
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
88
|
-
|
87
|
+
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
89
88
|
end
|
90
89
|
|
91
90
|
# This method sets the Double to have a dont_allow strategy.
|
@@ -105,11 +104,11 @@ module RR
|
|
105
104
|
# m.method3.with_no_args # Do not allow method3 with no arguments
|
106
105
|
# end
|
107
106
|
def dont_allow(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
108
|
-
|
109
|
-
proxy_when_dont_allow_error
|
107
|
+
verify_no_strategy
|
108
|
+
proxy_when_dont_allow_error if @using_proxy_strategy
|
110
109
|
@strategy = :dont_allow
|
111
110
|
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
112
|
-
|
111
|
+
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
113
112
|
end
|
114
113
|
alias_method :do_not_allow, :dont_allow
|
115
114
|
alias_method :dont_call, :dont_allow
|
@@ -161,10 +160,10 @@ module RR
|
|
161
160
|
# "My new return value"
|
162
161
|
# end
|
163
162
|
def proxy(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
164
|
-
proxy_when_dont_allow_error
|
165
|
-
@
|
163
|
+
proxy_when_dont_allow_error if @strategy == :dont_allow
|
164
|
+
@using_proxy_strategy = true
|
166
165
|
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
167
|
-
|
166
|
+
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
168
167
|
end
|
169
168
|
alias_method :probe, :proxy
|
170
169
|
|
@@ -180,41 +179,41 @@ module RR
|
|
180
179
|
# projects[0..2]
|
181
180
|
# end
|
182
181
|
def instance_of(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
183
|
-
@
|
182
|
+
@instance_of_called = true
|
184
183
|
return self if subject === NO_SUBJECT_ARG
|
185
184
|
raise ArgumentError, "instance_of only accepts class objects" unless subject.is_a?(Class)
|
186
|
-
|
185
|
+
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
187
186
|
end
|
188
187
|
|
189
|
-
def create
|
188
|
+
def create(subject, method_name, *args, &handler)
|
190
189
|
@args = args
|
191
190
|
@handler = handler
|
192
|
-
if @
|
193
|
-
|
191
|
+
if @instance_of_called
|
192
|
+
setup_doubles_for_class_instances(subject, method_name)
|
194
193
|
else
|
195
194
|
setup_double(subject, method_name)
|
196
195
|
end
|
197
|
-
transform
|
196
|
+
transform
|
198
197
|
@definition
|
199
198
|
end
|
200
199
|
|
201
200
|
protected
|
202
201
|
def setup_double(subject, method_name)
|
203
202
|
@double_injection = @space.double_injection(subject, method_name)
|
204
|
-
@double =
|
203
|
+
@double = Double.new(@double_injection)
|
205
204
|
@definition = @double.definition
|
206
205
|
end
|
207
206
|
|
208
|
-
def
|
207
|
+
def setup_doubles_for_class_instances(subject, method_name)
|
209
208
|
class_double = @space.double_injection(subject, :new)
|
210
|
-
class_double =
|
209
|
+
class_double = Double.new(class_double)
|
211
210
|
|
212
211
|
instance_method_name = method_name
|
213
212
|
|
214
|
-
@definition =
|
215
|
-
class_handler =
|
213
|
+
@definition = DoubleDefinition.new
|
214
|
+
class_handler = lambda do |return_value|
|
216
215
|
double_injection = @space.double_injection(return_value, instance_method_name)
|
217
|
-
|
216
|
+
Double.new(double_injection, @definition)
|
218
217
|
return_value
|
219
218
|
end
|
220
219
|
|
@@ -223,42 +222,46 @@ module RR
|
|
223
222
|
[],
|
224
223
|
class_handler
|
225
224
|
)
|
226
|
-
builder.stub
|
227
|
-
builder.proxy
|
225
|
+
builder.stub
|
226
|
+
builder.proxy
|
228
227
|
end
|
229
228
|
|
230
|
-
def transform
|
229
|
+
def transform
|
231
230
|
builder = DoubleDefinitionBuilder.new(@definition, @args, @handler)
|
232
231
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
end
|
239
|
-
|
240
|
-
if @proxy
|
241
|
-
builder.proxy!
|
232
|
+
verify_strategy
|
233
|
+
builder.__send__(@strategy)
|
234
|
+
|
235
|
+
if @using_proxy_strategy
|
236
|
+
builder.proxy
|
242
237
|
else
|
243
|
-
builder.reimplementation
|
238
|
+
builder.reimplementation
|
244
239
|
end
|
245
240
|
end
|
246
241
|
|
247
|
-
def
|
242
|
+
def verify_no_strategy
|
243
|
+
strategy_already_defined_error if @strategy
|
244
|
+
end
|
245
|
+
|
246
|
+
def strategy_already_defined_error
|
248
247
|
raise(
|
249
248
|
DoubleDefinitionError,
|
250
249
|
"This Double already has a #{@strategy} strategy"
|
251
250
|
)
|
252
251
|
end
|
253
252
|
|
254
|
-
def
|
253
|
+
def verify_strategy
|
254
|
+
no_strategy_error unless @strategy
|
255
|
+
end
|
256
|
+
|
257
|
+
def no_strategy_error
|
255
258
|
raise(
|
256
259
|
DoubleDefinitionError,
|
257
260
|
"This Double has no strategy"
|
258
261
|
)
|
259
262
|
end
|
260
263
|
|
261
|
-
def proxy_when_dont_allow_error
|
264
|
+
def proxy_when_dont_allow_error
|
262
265
|
raise(
|
263
266
|
DoubleDefinitionError,
|
264
267
|
"Doubles cannot be proxied when using dont_allow strategy"
|