rr 0.4.3 → 0.4.4
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 +4 -0
- data/README +25 -0
- data/Rakefile +1 -1
- data/lib/rr/double.rb +10 -10
- data/lib/rr/double_creator.rb +5 -5
- data/lib/rr/double_injection.rb +7 -7
- data/lib/rr/double_method_proxy.rb +1 -2
- data/lib/rr/space.rb +21 -21
- data/lib/rr/wildcard_matchers/anything.rb +4 -0
- data/lib/rr/wildcard_matchers/boolean.rb +4 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +7 -0
- data/lib/rr/wildcard_matchers/is_a.rb +4 -0
- data/lib/rr/wildcard_matchers/numeric.rb +4 -0
- data/spec/high_level_spec.rb +14 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +16 -16
- data/spec/rr/double/double_injection_bind_spec.rb +47 -20
- data/spec/rr/double/double_injection_dispatching_spec.rb +26 -20
- data/spec/rr/double/double_injection_has_original_method_spec.rb +10 -11
- data/spec/rr/double/double_injection_register_scenario_spec.rb +6 -6
- data/spec/rr/double/double_injection_reset_spec.rb +11 -14
- data/spec/rr/double/double_injection_spec.rb +18 -12
- data/spec/rr/double/double_injection_verify_spec.rb +5 -5
- data/spec/rr/double_definition_spec.rb +5 -5
- data/spec/rr/double_method_proxy_spec.rb +5 -5
- data/spec/rr/double_spec.rb +48 -48
- data/spec/rr/expectations/anything_spec.rb +14 -0
- data/spec/rr/expectations/boolean_spec.rb +14 -0
- data/spec/rr/expectations/duck_type_spec.rb +14 -0
- data/spec/rr/expectations/is_a_spec.rb +14 -0
- data/spec/rr/expectations/numeric_spec.rb +14 -0
- data/spec/rr/expectations/range_spec.rb +10 -0
- data/spec/rr/expectations/regexp_spec.rb +10 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +3 -3
- data/spec/rr/rspec/rspec_adapter_spec.rb +12 -12
- data/spec/rr/space/space_create_spec.rb +27 -37
- data/spec/rr/space/space_register_spec.rb +3 -3
- data/spec/rr/space/space_reset_spec.rb +24 -24
- data/spec/rr/space/space_spec.rb +2 -2
- data/spec/rr/space/space_verify_spec.rb +18 -18
- metadata +9 -2
@@ -3,13 +3,13 @@ require "spec/spec_helper"
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
5
|
describe TimesCalledExpectation, :shared => true do
|
6
|
-
attr_reader :space, :object, :method_name, :
|
6
|
+
attr_reader :space, :object, :method_name, :double_injection, :double, :expectation
|
7
7
|
before do
|
8
8
|
@space = Space.new
|
9
9
|
@object = Object.new
|
10
10
|
@method_name = :foobar
|
11
|
-
@
|
12
|
-
@double = space.double(
|
11
|
+
@double_injection = space.double_injection(object, method_name)
|
12
|
+
@double = space.double(double_injection)
|
13
13
|
double.with_any_args
|
14
14
|
end
|
15
15
|
|
@@ -12,12 +12,12 @@ module RR
|
|
12
12
|
@method_name = :foobar
|
13
13
|
end
|
14
14
|
|
15
|
-
it "resets the
|
16
|
-
RR::Space.
|
17
|
-
RR::Space.
|
15
|
+
it "resets the double_injections" do
|
16
|
+
RR::Space.double_injection(@subject, @method_name)
|
17
|
+
RR::Space.double_injections.should_not be_empty
|
18
18
|
|
19
19
|
@fixture.setup_mocks_for_rspec
|
20
|
-
RR::Space.
|
20
|
+
RR::Space.double_injections.should be_empty
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -30,16 +30,16 @@ module RR
|
|
30
30
|
@method_name = :foobar
|
31
31
|
end
|
32
32
|
|
33
|
-
it "verifies the
|
34
|
-
|
35
|
-
double = RR::Space.double(
|
33
|
+
it "verifies the double_injections" do
|
34
|
+
double_injection = RR::Space.double_injection(@subject, @method_name)
|
35
|
+
double = RR::Space.double(double_injection)
|
36
36
|
|
37
37
|
double.once
|
38
38
|
|
39
39
|
proc do
|
40
40
|
@fixture.verify_mocks_for_rspec
|
41
41
|
end.should raise_error(::RR::Errors::TimesCalledError)
|
42
|
-
RR::Space.
|
42
|
+
RR::Space.double_injections.should be_empty
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -52,12 +52,12 @@ module RR
|
|
52
52
|
@method_name = :foobar
|
53
53
|
end
|
54
54
|
|
55
|
-
it "resets the
|
56
|
-
RR::Space.
|
57
|
-
RR::Space.
|
55
|
+
it "resets the double_injections" do
|
56
|
+
RR::Space.double_injection(@subject, @method_name)
|
57
|
+
RR::Space.double_injections.should_not be_empty
|
58
58
|
|
59
59
|
@fixture.teardown_mocks_for_rspec
|
60
|
-
RR::Space.
|
60
|
+
RR::Space.double_injections.should be_empty
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -14,14 +14,6 @@ module RR
|
|
14
14
|
proxy.should be_instance_of(DoubleMethodProxy)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "sets space to self" do
|
18
|
-
proxy = @space.double_method_proxy(@creator, @object)
|
19
|
-
class << proxy
|
20
|
-
attr_reader :space
|
21
|
-
end
|
22
|
-
proxy.space.should === @space
|
23
|
-
end
|
24
|
-
|
25
17
|
it "sets creator to passed in creator" do
|
26
18
|
proxy = @space.double_method_proxy(@creator, @object)
|
27
19
|
class << proxy
|
@@ -186,38 +178,38 @@ module RR
|
|
186
178
|
@method_name = :foobar
|
187
179
|
end
|
188
180
|
|
189
|
-
it "creates a Double and registers it to the
|
190
|
-
|
191
|
-
def
|
181
|
+
it "creates a Double and registers it to the double_injection" do
|
182
|
+
double_injection = @space.double_injection(@object, @method_name)
|
183
|
+
def double_injection.doubles
|
192
184
|
@doubles
|
193
185
|
end
|
194
186
|
|
195
|
-
double = @space.double(
|
196
|
-
|
187
|
+
double = @space.double(double_injection)
|
188
|
+
double_injection.doubles.should include(double)
|
197
189
|
end
|
198
190
|
end
|
199
191
|
|
200
|
-
describe Space, "#
|
192
|
+
describe Space, "#double_injection" do
|
201
193
|
it_should_behave_like "RR::Space"
|
202
194
|
|
203
195
|
before do
|
204
196
|
@space = Space.new
|
205
197
|
end
|
206
198
|
|
207
|
-
it "creates a new
|
199
|
+
it "creates a new double_injection when existing object == but not === with the same method name" do
|
208
200
|
object1 = []
|
209
201
|
object2 = []
|
210
202
|
(object1 === object2).should be_true
|
211
203
|
object1.__id__.should_not == object2.__id__
|
212
204
|
|
213
|
-
double1 = @space.
|
214
|
-
double2 = @space.
|
205
|
+
double1 = @space.double_injection(object1, :foobar)
|
206
|
+
double2 = @space.double_injection(object2, :foobar)
|
215
207
|
|
216
208
|
double1.should_not == double2
|
217
209
|
end
|
218
210
|
end
|
219
211
|
|
220
|
-
describe Space, "#
|
212
|
+
describe Space, "#double_injection when double_injection does not exist" do
|
221
213
|
it_should_behave_like "RR::Space"
|
222
214
|
|
223
215
|
before do
|
@@ -229,29 +221,27 @@ module RR
|
|
229
221
|
@method_name = :foobar
|
230
222
|
end
|
231
223
|
|
232
|
-
it "returns
|
233
|
-
|
234
|
-
@space.
|
235
|
-
|
236
|
-
|
237
|
-
double_insertion.method_name.should === @method_name
|
224
|
+
it "returns double_injection and adds double_injection to double_injection list when method_name is a symbol" do
|
225
|
+
double_injection = @space.double_injection(@object, @method_name)
|
226
|
+
@space.double_injection(@object, @method_name).should === double_injection
|
227
|
+
double_injection.object.should === @object
|
228
|
+
double_injection.method_name.should === @method_name
|
238
229
|
end
|
239
230
|
|
240
|
-
it "returns
|
241
|
-
|
242
|
-
@space.
|
243
|
-
|
244
|
-
|
245
|
-
double_insertion.method_name.should === @method_name
|
231
|
+
it "returns double_injection and adds double_injection to double_injection list when method_name is a string" do
|
232
|
+
double_injection = @space.double_injection(@object, 'foobar')
|
233
|
+
@space.double_injection(@object, @method_name).should === double_injection
|
234
|
+
double_injection.object.should === @object
|
235
|
+
double_injection.method_name.should === @method_name
|
246
236
|
end
|
247
237
|
|
248
238
|
it "overrides the method when passing a block" do
|
249
|
-
|
239
|
+
double_injection = @space.double_injection(@object, @method_name)
|
250
240
|
@object.methods.should include("__rr__#{@method_name}")
|
251
241
|
end
|
252
242
|
end
|
253
243
|
|
254
|
-
describe Space, "#
|
244
|
+
describe Space, "#double_injection when double_injection exists" do
|
255
245
|
it_should_behave_like "RR::Space"
|
256
246
|
|
257
247
|
before do
|
@@ -263,15 +253,15 @@ module RR
|
|
263
253
|
@method_name = :foobar
|
264
254
|
end
|
265
255
|
|
266
|
-
it "returns the existing
|
256
|
+
it "returns the existing double_injection" do
|
267
257
|
original_foobar_method = @object.method(:foobar)
|
268
|
-
|
258
|
+
double_injection = @space.double_injection(@object, 'foobar')
|
269
259
|
|
270
|
-
|
260
|
+
double_injection.object_has_original_method?.should be_true
|
271
261
|
|
272
|
-
@space.
|
262
|
+
@space.double_injection(@object, 'foobar').should === double_injection
|
273
263
|
|
274
|
-
|
264
|
+
double_injection.reset
|
275
265
|
@object.foobar.should == :original_foobar
|
276
266
|
end
|
277
267
|
end
|
@@ -10,7 +10,7 @@ module RR
|
|
10
10
|
Space.instance = @space
|
11
11
|
@object = Object.new
|
12
12
|
@method_name = :foobar
|
13
|
-
@
|
13
|
+
@double_injection = @space.double_injection(@object, @method_name)
|
14
14
|
end
|
15
15
|
|
16
16
|
after(:each) do
|
@@ -18,13 +18,13 @@ module RR
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "adds the ordered double to the ordered_doubles collection" do
|
21
|
-
double1 = @space.double(@
|
21
|
+
double1 = @space.double(@double_injection)
|
22
22
|
|
23
23
|
@space.ordered_doubles.should == []
|
24
24
|
@space.register_ordered_double double1
|
25
25
|
@space.ordered_doubles.should == [double1]
|
26
26
|
|
27
|
-
double2 = @space.double(@
|
27
|
+
double2 = @space.double(@double_injection)
|
28
28
|
@space.register_ordered_double double2
|
29
29
|
@space.ordered_doubles.should == [double1, double2]
|
30
30
|
end
|
@@ -12,8 +12,8 @@ module RR
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "removes the ordered doubles" do
|
15
|
-
double1 = @space.
|
16
|
-
double2 = @space.
|
15
|
+
double1 = @space.double_injection(@object1, :foobar1)
|
16
|
+
double2 = @space.double_injection(@object1, :foobar2)
|
17
17
|
|
18
18
|
double1 = @space.double(double1)
|
19
19
|
double2 = @space.double(double2)
|
@@ -27,8 +27,8 @@ module RR
|
|
27
27
|
@space.ordered_doubles.should be_empty
|
28
28
|
end
|
29
29
|
|
30
|
-
it "resets all
|
31
|
-
double1 = @space.
|
30
|
+
it "resets all double_injections" do
|
31
|
+
double1 = @space.double_injection(@object1, @method_name)
|
32
32
|
double1_reset_calls = 0
|
33
33
|
(
|
34
34
|
class << double1;
|
@@ -38,7 +38,7 @@ module RR
|
|
38
38
|
double1_reset_calls += 1
|
39
39
|
end
|
40
40
|
end
|
41
|
-
double2 = @space.
|
41
|
+
double2 = @space.double_injection(@object2, @method_name)
|
42
42
|
double2_reset_calls = 0
|
43
43
|
(
|
44
44
|
class << double2;
|
@@ -62,35 +62,35 @@ module RR
|
|
62
62
|
@method_name = :foobar
|
63
63
|
end
|
64
64
|
|
65
|
-
it "resets the
|
66
|
-
|
67
|
-
@space.
|
65
|
+
it "resets the double_injections" do
|
66
|
+
double_injection = @space.double_injection(@object, @method_name)
|
67
|
+
@space.double_injections[@object][@method_name].should === double_injection
|
68
68
|
@object.methods.should include("__rr__#{@method_name}")
|
69
69
|
|
70
70
|
@space.reset_double(@object, @method_name)
|
71
|
-
@space.
|
71
|
+
@space.double_injections[@object][@method_name].should be_nil
|
72
72
|
@object.methods.should_not include("__rr__#{@method_name}")
|
73
73
|
end
|
74
74
|
|
75
|
-
it "removes the object from the
|
76
|
-
double1 = @space.
|
77
|
-
double2 = @space.
|
75
|
+
it "removes the object from the double_injections map when it has no double_injections" do
|
76
|
+
double1 = @space.double_injection(@object, :foobar1)
|
77
|
+
double2 = @space.double_injection(@object, :foobar2)
|
78
78
|
|
79
|
-
@space.
|
80
|
-
@space.
|
81
|
-
@space.
|
79
|
+
@space.double_injections.include?(@object).should == true
|
80
|
+
@space.double_injections[@object][:foobar1].should_not be_nil
|
81
|
+
@space.double_injections[@object][:foobar2].should_not be_nil
|
82
82
|
|
83
83
|
@space.reset_double(@object, :foobar1)
|
84
|
-
@space.
|
85
|
-
@space.
|
86
|
-
@space.
|
84
|
+
@space.double_injections.include?(@object).should == true
|
85
|
+
@space.double_injections[@object][:foobar1].should be_nil
|
86
|
+
@space.double_injections[@object][:foobar2].should_not be_nil
|
87
87
|
|
88
88
|
@space.reset_double(@object, :foobar2)
|
89
|
-
@space.
|
89
|
+
@space.double_injections.include?(@object).should == false
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe "#
|
93
|
+
describe "#reset_double_injections" do
|
94
94
|
it_should_behave_like "RR::Space"
|
95
95
|
|
96
96
|
before do
|
@@ -100,8 +100,8 @@ module RR
|
|
100
100
|
@method_name = :foobar
|
101
101
|
end
|
102
102
|
|
103
|
-
it "resets the
|
104
|
-
double1 = @space.
|
103
|
+
it "resets the double_injection and removes it from the double_injections list" do
|
104
|
+
double1 = @space.double_injection(@object1, @method_name)
|
105
105
|
double1_reset_calls = 0
|
106
106
|
(
|
107
107
|
class << double1;
|
@@ -111,7 +111,7 @@ module RR
|
|
111
111
|
double1_reset_calls += 1
|
112
112
|
end
|
113
113
|
end
|
114
|
-
double2 = @space.
|
114
|
+
double2 = @space.double_injection(@object2, @method_name)
|
115
115
|
double2_reset_calls = 0
|
116
116
|
(
|
117
117
|
class << double2;
|
@@ -122,7 +122,7 @@ module RR
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
@space.send(:
|
125
|
+
@space.send(:reset_double_injections)
|
126
126
|
double1_reset_calls.should == 1
|
127
127
|
double2_reset_calls.should == 1
|
128
128
|
end
|
data/spec/rr/space/space_spec.rb
CHANGED
@@ -20,12 +20,12 @@ module RR
|
|
20
20
|
class << @space;
|
21
21
|
self;
|
22
22
|
end).class_eval do
|
23
|
-
define_method :
|
23
|
+
define_method :double_injection do |*args|
|
24
24
|
create_double_args = args
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
Space.
|
28
|
+
Space.double_injection(:foo, :bar)
|
29
29
|
create_double_args.should == [:foo, :bar]
|
30
30
|
end
|
31
31
|
end
|
@@ -6,11 +6,11 @@ module RR
|
|
6
6
|
@space = Space.new
|
7
7
|
@object = Object.new
|
8
8
|
@method_name = :foobar
|
9
|
-
@
|
9
|
+
@double_injection = @space.double_injection(@object, @method_name)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raises an error when Double is NonTerminal" do
|
13
|
-
double = @space.double(@
|
13
|
+
double = @space.double(@double_injection)
|
14
14
|
@space.register_ordered_double(double)
|
15
15
|
|
16
16
|
double.any_number_of_times
|
@@ -36,8 +36,8 @@ module RR
|
|
36
36
|
@method_name = :foobar
|
37
37
|
end
|
38
38
|
|
39
|
-
it "verifies and deletes the
|
40
|
-
double1 = @space.
|
39
|
+
it "verifies and deletes the double_injections" do
|
40
|
+
double1 = @space.double_injection(@object1, @method_name)
|
41
41
|
double1_verify_calls = 0
|
42
42
|
double1_reset_calls = 0
|
43
43
|
(
|
@@ -51,7 +51,7 @@ module RR
|
|
51
51
|
double1_reset_calls += 1
|
52
52
|
end
|
53
53
|
end
|
54
|
-
double2 = @space.
|
54
|
+
double2 = @space.double_injection(@object2, @method_name)
|
55
55
|
double2_verify_calls = 0
|
56
56
|
double2_reset_calls = 0
|
57
57
|
(
|
@@ -83,14 +83,14 @@ module RR
|
|
83
83
|
@method_name = :foobar
|
84
84
|
end
|
85
85
|
|
86
|
-
it "verifies and deletes the
|
87
|
-
|
88
|
-
@space.
|
86
|
+
it "verifies and deletes the double_injection" do
|
87
|
+
double_injection = @space.double_injection(@object, @method_name)
|
88
|
+
@space.double_injections[@object][@method_name].should === double_injection
|
89
89
|
@object.methods.should include("__rr__#{@method_name}")
|
90
90
|
|
91
91
|
verify_calls = 0
|
92
92
|
(
|
93
|
-
class <<
|
93
|
+
class << double_injection;
|
94
94
|
self;
|
95
95
|
end).class_eval do
|
96
96
|
define_method(:verify) do ||
|
@@ -100,18 +100,18 @@ module RR
|
|
100
100
|
@space.verify_double(@object, @method_name)
|
101
101
|
verify_calls.should == 1
|
102
102
|
|
103
|
-
@space.
|
103
|
+
@space.double_injections[@object][@method_name].should be_nil
|
104
104
|
@object.methods.should_not include("__rr__#{@method_name}")
|
105
105
|
end
|
106
106
|
|
107
|
-
it "deletes the
|
108
|
-
|
109
|
-
@space.
|
107
|
+
it "deletes the double_injection when verifying the double_injection raises an error" do
|
108
|
+
double_injection = @space.double_injection(@object, @method_name)
|
109
|
+
@space.double_injections[@object][@method_name].should === double_injection
|
110
110
|
@object.methods.should include("__rr__#{@method_name}")
|
111
111
|
|
112
112
|
verify_called = true
|
113
113
|
(
|
114
|
-
class <<
|
114
|
+
class << double_injection;
|
115
115
|
self;
|
116
116
|
end).class_eval do
|
117
117
|
define_method(:verify) do ||
|
@@ -122,7 +122,7 @@ module RR
|
|
122
122
|
proc {@space.verify_double(@object, @method_name)}.should raise_error
|
123
123
|
verify_called.should be_true
|
124
124
|
|
125
|
-
@space.
|
125
|
+
@space.double_injections[@object][@method_name].should be_nil
|
126
126
|
@object.methods.should_not include("__rr__#{@method_name}")
|
127
127
|
end
|
128
128
|
end
|
@@ -131,7 +131,7 @@ module RR
|
|
131
131
|
it_should_behave_like "RR::Space#verify_ordered_double"
|
132
132
|
|
133
133
|
it "keeps the double when times called is not verified" do
|
134
|
-
double = @space.double(@
|
134
|
+
double = @space.double(@double_injection)
|
135
135
|
@space.register_ordered_double(double)
|
136
136
|
|
137
137
|
double.twice
|
@@ -142,7 +142,7 @@ module RR
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it "removes the double when times called expectation should no longer be attempted" do
|
145
|
-
double = @space.double(@
|
145
|
+
double = @space.double(@double_injection)
|
146
146
|
@space.register_ordered_double(double)
|
147
147
|
|
148
148
|
double.with(1).once
|
@@ -172,7 +172,7 @@ module RR
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def double
|
175
|
-
double_definition = @space.double(@
|
175
|
+
double_definition = @space.double(@double_injection).once
|
176
176
|
@space.register_ordered_double(double_definition.double)
|
177
177
|
double_definition.double
|
178
178
|
end
|