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.
- data/CHANGES +14 -0
- data/README.rdoc +67 -13
- data/Rakefile +1 -1
- data/lib/rr.rb +29 -9
- data/lib/rr/adapters/rr_methods.rb +38 -158
- data/lib/rr/double.rb +46 -41
- data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
- data/lib/rr/double_definitions/double_definition.rb +212 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -0
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
- data/lib/rr/double_injection.rb +21 -15
- data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
- data/lib/rr/space.rb +23 -22
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/high_level_spec.rb +111 -64
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
- data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
- data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
- data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
- data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
- data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
- data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
- data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
- data/spec/rr/double_injection/double_injection_spec.rb +77 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +156 -136
- data/spec/rr/errors/rr_error_spec.rb +1 -1
- data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
- data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/rr/expectations/hash_including_spec.rb +17 -0
- data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/satisfy_spec.rb +14 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +30 -28
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
- data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
- data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
- data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +330 -192
- data/spec/rr/test_unit/test_helper.rb +1 -2
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
- data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
- data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
- data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
- data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
- data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
- data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
- data/spec/rr_spec.rb +28 -0
- data/spec/spec_helper.rb +84 -0
- metadata +43 -29
- data/lib/rr/double_creator.rb +0 -271
- data/lib/rr/double_definition.rb +0 -179
- data/lib/rr/double_definition_builder.rb +0 -44
- data/lib/rr/double_definition_creator.rb +0 -156
- data/lib/rr/double_definition_creator_proxy.rb +0 -20
- data/spec/rr/double/double_injection_bind_spec.rb +0 -105
- data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
- data/spec/rr/double/double_injection_reset_spec.rb +0 -86
- data/spec/rr/double/double_injection_spec.rb +0 -72
- data/spec/rr/double/double_injection_verify_spec.rb +0 -24
- data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
- data/spec/rr/double_definition_creator_spec.rb +0 -496
- data/spec/rr/double_definition_spec.rb +0 -815
- data/spec/rr/expectations/anything_spec.rb +0 -14
- data/spec/rr/expectations/boolean_spec.rb +0 -14
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
- data/spec/rr/expectations/duck_type_spec.rb +0 -14
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
- data/spec/rr/expectations/is_a_spec.rb +0 -14
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
- data/spec/rr/expectations/numeric_spec.rb +0 -14
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
- data/spec/rr/expectations/range_spec.rb +0 -10
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
- data/spec/rr/expectations/regexp_spec.rb +0 -10
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Takita
|
@@ -9,7 +9,7 @@ autorequire: rr
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-13 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,10 +37,24 @@ files:
|
|
37
37
|
- lib/rr/times_called_matchers/terminal.rb
|
38
38
|
- lib/rr/times_called_matchers/range_matcher.rb
|
39
39
|
- lib/rr/hash_with_object_id_key.rb
|
40
|
-
- lib/rr/double_creator.rb
|
41
40
|
- lib/rr/expectations/argument_equality_expectation.rb
|
42
41
|
- lib/rr/expectations/times_called_expectation.rb
|
43
42
|
- lib/rr/expectations/any_argument_expectation.rb
|
43
|
+
- lib/rr/double_definitions/child_double_definition_creator.rb
|
44
|
+
- lib/rr/double_definitions/double_definition.rb
|
45
|
+
- lib/rr/double_definitions/strategies/scope/instance_of_class.rb
|
46
|
+
- lib/rr/double_definitions/strategies/scope/instance.rb
|
47
|
+
- lib/rr/double_definitions/strategies/scope/scope_strategy.rb
|
48
|
+
- lib/rr/double_definitions/strategies/verification/mock.rb
|
49
|
+
- lib/rr/double_definitions/strategies/verification/stub.rb
|
50
|
+
- lib/rr/double_definitions/strategies/verification/dont_allow.rb
|
51
|
+
- lib/rr/double_definitions/strategies/verification/verification_strategy.rb
|
52
|
+
- lib/rr/double_definitions/strategies/strategy.rb
|
53
|
+
- lib/rr/double_definitions/strategies/implementation/proxy.rb
|
54
|
+
- lib/rr/double_definitions/strategies/implementation/reimplementation.rb
|
55
|
+
- lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb
|
56
|
+
- lib/rr/double_definitions/double_definition_creator.rb
|
57
|
+
- lib/rr/double_definitions/double_definition_creator_proxy.rb
|
44
58
|
- lib/rr/double_matches.rb
|
45
59
|
- lib/rr/errors/double_definition_error.rb
|
46
60
|
- lib/rr/errors/argument_equality_error.rb
|
@@ -48,32 +62,37 @@ files:
|
|
48
62
|
- lib/rr/errors/rr_error.rb
|
49
63
|
- lib/rr/errors/times_called_error.rb
|
50
64
|
- lib/rr/errors/double_order_error.rb
|
51
|
-
- lib/rr/double_definition_builder.rb
|
52
65
|
- lib/rr/adapters/rr_methods.rb
|
53
66
|
- lib/rr/adapters/test_unit.rb
|
54
67
|
- lib/rr/adapters/rspec.rb
|
55
|
-
- lib/rr/double_definition.rb
|
56
|
-
- lib/rr/double_definition_creator.rb
|
57
68
|
- lib/rr/double_injection.rb
|
58
69
|
- lib/rr/space.rb
|
59
70
|
- lib/rr/wildcard_matchers/boolean.rb
|
60
71
|
- lib/rr/wildcard_matchers/duck_type.rb
|
61
72
|
- lib/rr/wildcard_matchers/range.rb
|
73
|
+
- lib/rr/wildcard_matchers/satisfy.rb
|
62
74
|
- lib/rr/wildcard_matchers/regexp.rb
|
63
75
|
- lib/rr/wildcard_matchers/numeric.rb
|
64
76
|
- lib/rr/wildcard_matchers/is_a.rb
|
77
|
+
- lib/rr/wildcard_matchers/hash_including.rb
|
65
78
|
- lib/rr/wildcard_matchers/anything.rb
|
66
|
-
- lib/rr/double_definition_creator_proxy.rb
|
67
79
|
- lib/rr/double.rb
|
68
80
|
- spec/environment_fixture_setup.rb
|
69
81
|
- spec/spec_suite.rb
|
70
82
|
- spec/test_unit_spec_suite.rb
|
71
83
|
- spec/spec_helper.rb
|
72
84
|
- spec/high_level_spec.rb
|
85
|
+
- spec/rr_spec.rb
|
73
86
|
- spec/rr/rspec/rspec_backtrace_tweaking_spec.rb
|
74
87
|
- spec/rr/rspec/rspec_usage_spec.rb
|
75
88
|
- spec/rr/rspec/rspec_adapter_spec.rb
|
76
89
|
- spec/rr/double_spec.rb
|
90
|
+
- spec/rr/double_injection/double_injection_has_original_method_spec.rb
|
91
|
+
- spec/rr/double_injection/double_injection_spec.rb
|
92
|
+
- spec/rr/double_injection/double_injection_bind_spec.rb
|
93
|
+
- spec/rr/double_injection/double_injection_dispatching_spec.rb
|
94
|
+
- spec/rr/double_injection/double_injection_verify_spec.rb
|
95
|
+
- spec/rr/double_injection/double_injection_reset_spec.rb
|
77
96
|
- spec/rr/times_called_matchers/proc_matcher_spec.rb
|
78
97
|
- spec/rr/times_called_matchers/any_times_matcher_spec.rb
|
79
98
|
- spec/rr/times_called_matchers/range_matcher_spec.rb
|
@@ -83,6 +102,7 @@ files:
|
|
83
102
|
- spec/rr/times_called_matchers/integer_matcher_spec.rb
|
84
103
|
- spec/rr/space/hash_with_object_id_key_spec.rb
|
85
104
|
- spec/rr/space/space_spec.rb
|
105
|
+
- spec/rr/expectations/satisfy_spec.rb
|
86
106
|
- spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb
|
87
107
|
- spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb
|
88
108
|
- spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb
|
@@ -91,37 +111,30 @@ files:
|
|
91
111
|
- spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb
|
92
112
|
- spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb
|
93
113
|
- spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb
|
94
|
-
- spec/rr/expectations/numeric_spec.rb
|
95
|
-
- spec/rr/expectations/duck_type_spec.rb
|
96
|
-
- spec/rr/expectations/boolean_spec.rb
|
97
114
|
- spec/rr/expectations/boolean_argument_equality_expectation_spec.rb
|
98
|
-
- spec/rr/expectations/regexp_argument_equality_expectation_spec.rb
|
99
115
|
- spec/rr/expectations/anything_argument_equality_expectation_spec.rb
|
100
|
-
- spec/rr/expectations/
|
101
|
-
- spec/rr/expectations/range_spec.rb
|
116
|
+
- spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb
|
102
117
|
- spec/rr/expectations/any_argument_expectation_spec.rb
|
103
|
-
- spec/rr/expectations/
|
118
|
+
- spec/rr/expectations/hash_including_spec.rb
|
104
119
|
- spec/rr/expectations/argument_equality_expectation_spec.rb
|
105
|
-
- spec/rr/expectations/
|
106
|
-
- spec/rr/
|
107
|
-
- spec/rr/
|
108
|
-
- spec/rr/
|
109
|
-
- spec/rr/
|
120
|
+
- spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb
|
121
|
+
- spec/rr/double_definitions/child_double_definition_creator_spec.rb
|
122
|
+
- spec/rr/double_definitions/double_definition_spec.rb
|
123
|
+
- spec/rr/double_definitions/double_definition_creator_proxy_spec.rb
|
124
|
+
- spec/rr/double_definitions/double_definition_creator_spec.rb
|
110
125
|
- spec/rr/errors/rr_error_spec.rb
|
111
126
|
- spec/rr/adapters/rr_methods_spec_helper.rb
|
112
127
|
- spec/rr/adapters/rr_methods_times_matcher_spec.rb
|
113
128
|
- spec/rr/adapters/rr_methods_space_spec.rb
|
114
129
|
- spec/rr/adapters/rr_methods_creator_spec.rb
|
115
130
|
- spec/rr/adapters/rr_methods_argument_matcher_spec.rb
|
116
|
-
- spec/rr/
|
117
|
-
- spec/rr/
|
118
|
-
- spec/rr/
|
119
|
-
- spec/rr/
|
120
|
-
- spec/rr/
|
121
|
-
- spec/rr/
|
122
|
-
- spec/rr/
|
123
|
-
- spec/rr/double/double_injection_verify_spec.rb
|
124
|
-
- spec/rr/double/double_injection_reset_spec.rb
|
131
|
+
- spec/rr/wildcard_matchers/numeric_spec.rb
|
132
|
+
- spec/rr/wildcard_matchers/duck_type_spec.rb
|
133
|
+
- spec/rr/wildcard_matchers/boolean_spec.rb
|
134
|
+
- spec/rr/wildcard_matchers/range_spec.rb
|
135
|
+
- spec/rr/wildcard_matchers/regexp_spec.rb
|
136
|
+
- spec/rr/wildcard_matchers/is_a_spec.rb
|
137
|
+
- spec/rr/wildcard_matchers/anything_spec.rb
|
125
138
|
- spec/rr/test_unit/test_unit_backtrace_test.rb
|
126
139
|
- spec/rr/test_unit/test_helper.rb
|
127
140
|
- spec/rr/test_unit/test_unit_integration_test.rb
|
@@ -152,9 +165,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
165
|
requirements: []
|
153
166
|
|
154
167
|
rubyforge_project: pivotalrb
|
155
|
-
rubygems_version: 1.
|
168
|
+
rubygems_version: 1.2.0
|
156
169
|
signing_key:
|
157
170
|
specification_version: 2
|
158
171
|
summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
|
159
172
|
test_files:
|
160
173
|
- spec/high_level_spec.rb
|
174
|
+
- spec/rr_spec.rb
|
data/lib/rr/double_creator.rb
DELETED
@@ -1,271 +0,0 @@
|
|
1
|
-
module RR
|
2
|
-
# RR::DoubleDefinitionCreator provides a strategies to create a Double.
|
3
|
-
# The strategies are:
|
4
|
-
# * mock
|
5
|
-
# * stub
|
6
|
-
# * proxy
|
7
|
-
# * dont_allow
|
8
|
-
class DoubleDefinitionCreator
|
9
|
-
NO_SUBJECT_ARG = Object.new
|
10
|
-
|
11
|
-
attr_reader :space
|
12
|
-
include Errors
|
13
|
-
|
14
|
-
def initialize(space)
|
15
|
-
@space = space
|
16
|
-
@strategy = nil
|
17
|
-
@using_proxy_strategy = false
|
18
|
-
@instance_of_called = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
# This method sets the Double to have a mock strategy. A mock strategy
|
22
|
-
# sets the default state of the Double to expect the method call
|
23
|
-
# with arguments exactly one time. The Double's expectations can be
|
24
|
-
# changed.
|
25
|
-
#
|
26
|
-
# This method can be chained with proxy.
|
27
|
-
# mock.proxy(subject).method_name_1
|
28
|
-
# or
|
29
|
-
# proxy.mock(subject).method_name_1
|
30
|
-
#
|
31
|
-
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
32
|
-
# a method with arguments to the proxy will set up expectations that
|
33
|
-
# the a call to the subject's method with the arguments will happen.
|
34
|
-
# mock(subject).method_name_1 {return_value_1}
|
35
|
-
# mock(subject).method_name_2(arg1, arg2) {return_value_2}
|
36
|
-
#
|
37
|
-
# When passed the subject and the method_name, this method returns
|
38
|
-
# a mock Double with the method already set.
|
39
|
-
#
|
40
|
-
# mock(subject, :method_name_1) {return_value_1}
|
41
|
-
# mock(subject, :method_name_2).with(arg1, arg2) {return_value_2}
|
42
|
-
#
|
43
|
-
# mock also takes a block for definitions.
|
44
|
-
# mock(subject) do
|
45
|
-
# method_name_1 {return_value_1}
|
46
|
-
# method_name_2(arg_1, arg_2) {return_value_2}
|
47
|
-
# end
|
48
|
-
def mock(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
49
|
-
verify_no_strategy
|
50
|
-
@strategy = :mock
|
51
|
-
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
52
|
-
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
53
|
-
end
|
54
|
-
|
55
|
-
# This method sets the Double to have a stub strategy. A stub strategy
|
56
|
-
# sets the default state of the Double to expect the method call
|
57
|
-
# with any arguments any number of times. The Double's
|
58
|
-
# expectations can be changed.
|
59
|
-
#
|
60
|
-
# This method can be chained with proxy.
|
61
|
-
# stub.proxy(subject).method_name_1
|
62
|
-
# or
|
63
|
-
# proxy.stub(subject).method_name_1
|
64
|
-
#
|
65
|
-
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
66
|
-
# a method with arguments to the proxy will set up expectations that
|
67
|
-
# the a call to the subject's method with the arguments will happen,
|
68
|
-
# and return the prescribed value.
|
69
|
-
# stub(subject).method_name_1 {return_value_1}
|
70
|
-
# stub(subject).method_name_2(arg_1, arg_2) {return_value_2}
|
71
|
-
#
|
72
|
-
# When passed the subject and the method_name, this method returns
|
73
|
-
# a stub Double with the method already set.
|
74
|
-
#
|
75
|
-
# mock(subject, :method_name_1) {return_value_1}
|
76
|
-
# mock(subject, :method_name_2).with(arg1, arg2) {return_value_2}
|
77
|
-
#
|
78
|
-
# stub also takes a block for definitions.
|
79
|
-
# stub(subject) do
|
80
|
-
# method_name_1 {return_value_1}
|
81
|
-
# method_name_2(arg_1, arg_2) {return_value_2}
|
82
|
-
# end
|
83
|
-
def stub(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
84
|
-
verify_no_strategy
|
85
|
-
@strategy = :stub
|
86
|
-
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
87
|
-
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
88
|
-
end
|
89
|
-
|
90
|
-
# This method sets the Double to have a dont_allow strategy.
|
91
|
-
# A dont_allow strategy sets the default state of the Double
|
92
|
-
# to expect never to be called. The Double's expectations can be
|
93
|
-
# changed.
|
94
|
-
#
|
95
|
-
# The following example sets the expectation that subject.method_name
|
96
|
-
# will never be called with arg1 and arg2.
|
97
|
-
#
|
98
|
-
# dont_allow(subject).method_name(arg1, arg2)
|
99
|
-
#
|
100
|
-
# dont_allow also supports a block sytnax.
|
101
|
-
# dont_allow(subject) do |m|
|
102
|
-
# m.method1 # Do not allow method1 with any arguments
|
103
|
-
# m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
|
104
|
-
# m.method3.with_no_args # Do not allow method3 with no arguments
|
105
|
-
# end
|
106
|
-
def dont_allow(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
107
|
-
verify_no_strategy
|
108
|
-
proxy_when_dont_allow_error if @using_proxy_strategy
|
109
|
-
@strategy = :dont_allow
|
110
|
-
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
111
|
-
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
112
|
-
end
|
113
|
-
alias_method :do_not_allow, :dont_allow
|
114
|
-
alias_method :dont_call, :dont_allow
|
115
|
-
alias_method :do_not_call, :dont_allow
|
116
|
-
|
117
|
-
# This method add proxy capabilities to the Double. proxy can be called
|
118
|
-
# with mock or stub.
|
119
|
-
#
|
120
|
-
# mock.proxy(controller.template).render(:partial => "my/socks")
|
121
|
-
#
|
122
|
-
# stub.proxy(controller.template).render(:partial => "my/socks") do |html|
|
123
|
-
# html.should include("My socks are wet")
|
124
|
-
# html
|
125
|
-
# end
|
126
|
-
#
|
127
|
-
# mock.proxy(controller.template).render(:partial => "my/socks") do |html|
|
128
|
-
# html.should include("My socks are wet")
|
129
|
-
# "My new return value"
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
# mock.proxy also takes a block for definitions.
|
133
|
-
# mock.proxy(subject) do
|
134
|
-
# render(:partial => "my/socks")
|
135
|
-
#
|
136
|
-
# render(:partial => "my/socks") do |html|
|
137
|
-
# html.should include("My socks are wet")
|
138
|
-
# html
|
139
|
-
# end
|
140
|
-
#
|
141
|
-
# render(:partial => "my/socks") do |html|
|
142
|
-
# html.should include("My socks are wet")
|
143
|
-
# html
|
144
|
-
# end
|
145
|
-
#
|
146
|
-
# render(:partial => "my/socks") do |html|
|
147
|
-
# html.should include("My socks are wet")
|
148
|
-
# "My new return value"
|
149
|
-
# end
|
150
|
-
# end
|
151
|
-
#
|
152
|
-
# Passing a block to the Double (after the method name and arguments)
|
153
|
-
# allows you to intercept the return value.
|
154
|
-
# The return value can be modified, validated, and/or overridden by
|
155
|
-
# passing in a block. The return value of the block will replace
|
156
|
-
# the actual return value.
|
157
|
-
#
|
158
|
-
# mock.proxy(controller.template).render(:partial => "my/socks") do |html|
|
159
|
-
# html.should include("My socks are wet")
|
160
|
-
# "My new return value"
|
161
|
-
# end
|
162
|
-
def proxy(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
163
|
-
proxy_when_dont_allow_error if @strategy == :dont_allow
|
164
|
-
@using_proxy_strategy = true
|
165
|
-
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
166
|
-
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
167
|
-
end
|
168
|
-
alias_method :probe, :proxy
|
169
|
-
|
170
|
-
# Calling instance_of will cause all instances of the passed in Class
|
171
|
-
# to have the Double defined.
|
172
|
-
#
|
173
|
-
# The following example mocks all User's valid? method and return false.
|
174
|
-
# mock.instance_of(User).valid? {false}
|
175
|
-
#
|
176
|
-
# The following example mocks and proxies User#projects and returns the
|
177
|
-
# first 3 projects.
|
178
|
-
# mock.instance_of(User).projects do |projects|
|
179
|
-
# projects[0..2]
|
180
|
-
# end
|
181
|
-
def instance_of(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
|
182
|
-
@instance_of_called = true
|
183
|
-
return self if subject === NO_SUBJECT_ARG
|
184
|
-
raise ArgumentError, "instance_of only accepts class objects" unless subject.is_a?(Class)
|
185
|
-
DoubleDefinitionCreatorProxy.new(self, subject, method_name, &definition)
|
186
|
-
end
|
187
|
-
|
188
|
-
def create(subject, method_name, *args, &handler)
|
189
|
-
@args = args
|
190
|
-
@handler = handler
|
191
|
-
if @instance_of_called
|
192
|
-
setup_doubles_for_class_instances(subject, method_name)
|
193
|
-
else
|
194
|
-
setup_double(subject, method_name)
|
195
|
-
end
|
196
|
-
transform
|
197
|
-
@definition
|
198
|
-
end
|
199
|
-
|
200
|
-
protected
|
201
|
-
def setup_double(subject, method_name)
|
202
|
-
@double_injection = @space.double_injection(subject, method_name)
|
203
|
-
@double = Double.new(@double_injection)
|
204
|
-
@definition = @double.definition
|
205
|
-
end
|
206
|
-
|
207
|
-
def setup_doubles_for_class_instances(subject, method_name)
|
208
|
-
class_double = @space.double_injection(subject, :new)
|
209
|
-
class_double = Double.new(class_double)
|
210
|
-
|
211
|
-
instance_method_name = method_name
|
212
|
-
|
213
|
-
@definition = DoubleDefinition.new
|
214
|
-
class_handler = lambda do |return_value|
|
215
|
-
double_injection = @space.double_injection(return_value, instance_method_name)
|
216
|
-
Double.new(double_injection, @definition)
|
217
|
-
return_value
|
218
|
-
end
|
219
|
-
|
220
|
-
builder = DoubleDefinitionBuilder.new(
|
221
|
-
class_double.definition,
|
222
|
-
[],
|
223
|
-
class_handler
|
224
|
-
)
|
225
|
-
builder.stub
|
226
|
-
builder.proxy
|
227
|
-
end
|
228
|
-
|
229
|
-
def transform
|
230
|
-
builder = DoubleDefinitionBuilder.new(@definition, @args, @handler)
|
231
|
-
|
232
|
-
verify_strategy
|
233
|
-
builder.__send__(@strategy)
|
234
|
-
|
235
|
-
if @using_proxy_strategy
|
236
|
-
builder.proxy
|
237
|
-
else
|
238
|
-
builder.reimplementation
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def verify_no_strategy
|
243
|
-
strategy_already_defined_error if @strategy
|
244
|
-
end
|
245
|
-
|
246
|
-
def strategy_already_defined_error
|
247
|
-
raise(
|
248
|
-
DoubleDefinitionError,
|
249
|
-
"This Double already has a #{@strategy} strategy"
|
250
|
-
)
|
251
|
-
end
|
252
|
-
|
253
|
-
def verify_strategy
|
254
|
-
no_strategy_error unless @strategy
|
255
|
-
end
|
256
|
-
|
257
|
-
def no_strategy_error
|
258
|
-
raise(
|
259
|
-
DoubleDefinitionError,
|
260
|
-
"This Double has no strategy"
|
261
|
-
)
|
262
|
-
end
|
263
|
-
|
264
|
-
def proxy_when_dont_allow_error
|
265
|
-
raise(
|
266
|
-
DoubleDefinitionError,
|
267
|
-
"Doubles cannot be proxied when using dont_allow strategy"
|
268
|
-
)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
data/lib/rr/double_definition.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
module RR
|
2
|
-
class DoubleDefinition #:nodoc:
|
3
|
-
ORIGINAL_METHOD = Object.new
|
4
|
-
attr_accessor :times_called,
|
5
|
-
:argument_expectation,
|
6
|
-
:times_matcher,
|
7
|
-
:implementation,
|
8
|
-
:after_call_value,
|
9
|
-
:yields_value,
|
10
|
-
:double
|
11
|
-
attr_reader :block_callback_strategy
|
12
|
-
|
13
|
-
include Space::Reader
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@implementation = nil
|
17
|
-
@argument_expectation = nil
|
18
|
-
@times_matcher = nil
|
19
|
-
@after_call_value = nil
|
20
|
-
@yields_value = nil
|
21
|
-
returns_block_callback_strategy
|
22
|
-
end
|
23
|
-
|
24
|
-
def with(*args, &returns)
|
25
|
-
@argument_expectation = Expectations::ArgumentEqualityExpectation.new(*args)
|
26
|
-
install_method_callback returns
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def with_any_args(&returns)
|
31
|
-
@argument_expectation = Expectations::AnyArgumentExpectation.new
|
32
|
-
install_method_callback returns
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
def with_no_args(&returns)
|
37
|
-
@argument_expectation = Expectations::ArgumentEqualityExpectation.new()
|
38
|
-
install_method_callback returns
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def never
|
43
|
-
@times_matcher = TimesCalledMatchers::IntegerMatcher.new(0)
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
def once(&returns)
|
48
|
-
@times_matcher = TimesCalledMatchers::IntegerMatcher.new(1)
|
49
|
-
install_method_callback returns
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
def twice(&returns)
|
54
|
-
@times_matcher = TimesCalledMatchers::IntegerMatcher.new(2)
|
55
|
-
install_method_callback returns
|
56
|
-
self
|
57
|
-
end
|
58
|
-
|
59
|
-
def at_least(number, &returns)
|
60
|
-
@times_matcher = TimesCalledMatchers::AtLeastMatcher.new(number)
|
61
|
-
install_method_callback returns
|
62
|
-
self
|
63
|
-
end
|
64
|
-
|
65
|
-
def at_most(number, &returns)
|
66
|
-
@times_matcher = TimesCalledMatchers::AtMostMatcher.new(number)
|
67
|
-
install_method_callback returns
|
68
|
-
self
|
69
|
-
end
|
70
|
-
|
71
|
-
def any_number_of_times(&returns)
|
72
|
-
@times_matcher = TimesCalledMatchers::AnyTimesMatcher.new
|
73
|
-
install_method_callback returns
|
74
|
-
self
|
75
|
-
end
|
76
|
-
|
77
|
-
def times(matcher_value, &returns)
|
78
|
-
@times_matcher = TimesCalledMatchers::TimesCalledMatcher.create(matcher_value)
|
79
|
-
install_method_callback returns
|
80
|
-
self
|
81
|
-
end
|
82
|
-
|
83
|
-
def ordered(&returns)
|
84
|
-
raise(
|
85
|
-
Errors::DoubleDefinitionError,
|
86
|
-
"Double Definitions must have a dedicated Double to be ordered. " <<
|
87
|
-
"For example, using instance_of does not allow ordered to be used. " <<
|
88
|
-
"proxy the class's #new method instead."
|
89
|
-
) unless @double
|
90
|
-
@ordered = true
|
91
|
-
space.ordered_doubles << @double unless space.ordered_doubles.include?(@double)
|
92
|
-
install_method_callback returns
|
93
|
-
self
|
94
|
-
end
|
95
|
-
|
96
|
-
def ordered?
|
97
|
-
@ordered
|
98
|
-
end
|
99
|
-
|
100
|
-
def yields(*args, &returns)
|
101
|
-
@yields_value = args
|
102
|
-
install_method_callback returns
|
103
|
-
self
|
104
|
-
end
|
105
|
-
|
106
|
-
def after_call(&block)
|
107
|
-
raise ArgumentError, "after_call expects a block" unless block
|
108
|
-
@after_call_value = block
|
109
|
-
self
|
110
|
-
end
|
111
|
-
|
112
|
-
def verbose(&block)
|
113
|
-
@verbose = true
|
114
|
-
@after_call_value = block
|
115
|
-
self
|
116
|
-
end
|
117
|
-
|
118
|
-
def verbose?
|
119
|
-
@verbose ? true : false
|
120
|
-
end
|
121
|
-
|
122
|
-
def returns(*args, &implementation)
|
123
|
-
value = args.first
|
124
|
-
if !args.empty? && implementation
|
125
|
-
raise ArgumentError, "returns cannot accept both an argument and a block"
|
126
|
-
end
|
127
|
-
if implementation
|
128
|
-
implemented_by implementation
|
129
|
-
else
|
130
|
-
implemented_by lambda {value}
|
131
|
-
end
|
132
|
-
self
|
133
|
-
end
|
134
|
-
|
135
|
-
def proxy
|
136
|
-
implemented_by ORIGINAL_METHOD
|
137
|
-
self
|
138
|
-
end
|
139
|
-
|
140
|
-
def implemented_by(implementation)
|
141
|
-
@implementation = implementation
|
142
|
-
self
|
143
|
-
end
|
144
|
-
|
145
|
-
def exact_match?(*arguments)
|
146
|
-
return false unless @argument_expectation
|
147
|
-
@argument_expectation.exact_match?(*arguments)
|
148
|
-
end
|
149
|
-
|
150
|
-
def wildcard_match?(*arguments)
|
151
|
-
return false unless @argument_expectation
|
152
|
-
@argument_expectation.wildcard_match?(*arguments)
|
153
|
-
end
|
154
|
-
|
155
|
-
def terminal?
|
156
|
-
return false unless @times_matcher
|
157
|
-
@times_matcher.terminal?
|
158
|
-
end
|
159
|
-
|
160
|
-
def expected_arguments
|
161
|
-
return [] unless argument_expectation
|
162
|
-
argument_expectation.expected_arguments
|
163
|
-
end
|
164
|
-
|
165
|
-
def returns_block_callback_strategy # :nodoc:
|
166
|
-
@block_callback_strategy = :returns
|
167
|
-
end
|
168
|
-
|
169
|
-
def after_call_block_callback_strategy # :nodoc:
|
170
|
-
@block_callback_strategy = :after_call
|
171
|
-
end
|
172
|
-
|
173
|
-
protected
|
174
|
-
def install_method_callback(block)
|
175
|
-
return unless block
|
176
|
-
__send__(@block_callback_strategy, &block)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|