rr 0.4.8 → 0.4.9
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 +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
@@ -15,8 +15,8 @@ module RR
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
it "returns a
|
19
|
-
mock.should be_instance_of(
|
18
|
+
it "returns a DoubleDefinitionCreator when passed no arguments" do
|
19
|
+
mock.should be_instance_of(DoubleDefinitionCreator)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "sets up the RR mock call chain" do
|
@@ -36,7 +36,7 @@ module RR
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raises error if passed a method name and a block" do
|
39
|
-
|
39
|
+
lambda do
|
40
40
|
mock(@object, :foobar) {}
|
41
41
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
42
42
|
end
|
@@ -72,8 +72,8 @@ module RR
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
it "returns a
|
76
|
-
stub.should be_instance_of(
|
75
|
+
it "returns a DoubleDefinitionCreator when passed no arguments" do
|
76
|
+
stub.should be_instance_of(DoubleDefinitionCreator)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "sets up the RR stub call chain" do
|
@@ -93,7 +93,7 @@ module RR
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "raises error if passed a method name and a block" do
|
96
|
-
|
96
|
+
lambda do
|
97
97
|
stub(@object, :foobar) {}
|
98
98
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
99
99
|
end
|
@@ -125,8 +125,8 @@ module RR
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
it "#proxy returns a
|
129
|
-
proxy.should be_instance_of(
|
128
|
+
it "#proxy returns a DoubleDefinitionCreator when passed no arguments" do
|
129
|
+
proxy.should be_instance_of(DoubleDefinitionCreator)
|
130
130
|
end
|
131
131
|
|
132
132
|
it "#proxy sets up the RR proxy call chain" do
|
@@ -162,7 +162,7 @@ module RR
|
|
162
162
|
end
|
163
163
|
|
164
164
|
it "raises error if passed a method name and a block" do
|
165
|
-
|
165
|
+
lambda do
|
166
166
|
mock.proxy(@object, :foobar) {}
|
167
167
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
168
168
|
end
|
@@ -198,8 +198,8 @@ module RR
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
it "returns a
|
202
|
-
stub.proxy.should be_instance_of(
|
201
|
+
it "returns a DoubleDefinitionCreator when passed no arguments" do
|
202
|
+
stub.proxy.should be_instance_of(DoubleDefinitionCreator)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "sets up the RR proxy call chain" do
|
@@ -219,7 +219,7 @@ module RR
|
|
219
219
|
end
|
220
220
|
|
221
221
|
it "raises error if passed a method name and a block" do
|
222
|
-
|
222
|
+
lambda do
|
223
223
|
stub.proxy(@object, :foobar) {}
|
224
224
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
225
225
|
end
|
@@ -252,8 +252,8 @@ module RR
|
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
-
it "returns a
|
256
|
-
do_not_allow.should be_instance_of(
|
255
|
+
it "returns a DoubleDefinitionCreator when passed no arguments" do
|
256
|
+
do_not_allow.should be_instance_of(DoubleDefinitionCreator)
|
257
257
|
end
|
258
258
|
|
259
259
|
it "sets up the RR do_not_allow call chain" do
|
@@ -279,7 +279,7 @@ module RR
|
|
279
279
|
end
|
280
280
|
|
281
281
|
it "raises error if passed a method name and a block" do
|
282
|
-
|
282
|
+
lambda do
|
283
283
|
do_not_allow(@object, :foobar) {}
|
284
284
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
285
285
|
end
|
@@ -290,7 +290,7 @@ module RR
|
|
290
290
|
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
291
291
|
double.argument_expectation.expected_arguments.should == [1, 2]
|
292
292
|
|
293
|
-
|
293
|
+
lambda do
|
294
294
|
@subject.foobar(1, 2)
|
295
295
|
end.should raise_error(Errors::TimesCalledError)
|
296
296
|
reset
|
@@ -303,7 +303,7 @@ module RR
|
|
303
303
|
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
304
304
|
double.argument_expectation.expected_arguments.should == [1, 2]
|
305
305
|
|
306
|
-
|
306
|
+
lambda do
|
307
307
|
@subject.foobar(1, 2)
|
308
308
|
end.should raise_error(Errors::TimesCalledError)
|
309
309
|
reset
|
@@ -311,13 +311,13 @@ module RR
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
|
-
describe
|
314
|
+
describe DoubleDefinitionCreator, "#instance_of and #mock" do
|
315
315
|
before do
|
316
316
|
@klass = Class.new
|
317
317
|
end
|
318
318
|
|
319
|
-
it "returns a
|
320
|
-
instance_of.instance_of.should be_instance_of(
|
319
|
+
it "returns a DoubleDefinitionCreator when passed no arguments" do
|
320
|
+
instance_of.instance_of.should be_instance_of(DoubleDefinitionCreator)
|
321
321
|
end
|
322
322
|
|
323
323
|
it "sets up the RR instance_of call chain" do
|
@@ -337,7 +337,7 @@ module RR
|
|
337
337
|
end
|
338
338
|
|
339
339
|
it "raises error if passed a method name and a block" do
|
340
|
-
|
340
|
+
lambda do
|
341
341
|
instance_of.mock(@klass, :foobar) {}
|
342
342
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
343
343
|
end
|
@@ -87,8 +87,8 @@ module RR
|
|
87
87
|
double1 = @space.double_injection(@object1, :foobar1)
|
88
88
|
double2 = @space.double_injection(@object1, :foobar2)
|
89
89
|
|
90
|
-
double1 =
|
91
|
-
double2 =
|
90
|
+
double1 = Double.new(double1)
|
91
|
+
double2 = Double.new(double2)
|
92
92
|
|
93
93
|
double1.ordered
|
94
94
|
double2.ordered
|
@@ -22,7 +22,7 @@ module RR
|
|
22
22
|
yield(a, b)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
double =
|
25
|
+
double = Double.new(@double_injection)
|
26
26
|
double.with(1, 2).implemented_by(method_fixture.method(:method_with_block))
|
27
27
|
@object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
|
28
28
|
end
|
@@ -30,11 +30,11 @@ module RR
|
|
30
30
|
|
31
31
|
describe "where there are no doubles with duplicate ArgumentExpectations" do
|
32
32
|
it "dispatches to Double that have an exact match" do
|
33
|
-
double1_with_exact_match =
|
33
|
+
double1_with_exact_match = Double.new(@double_injection)
|
34
34
|
double1_with_exact_match.with(:exact_match_1).returns {:return_1}
|
35
|
-
double_with_no_match =
|
35
|
+
double_with_no_match = Double.new(@double_injection)
|
36
36
|
double_with_no_match.with("nothing that matches").returns {:no_match}
|
37
|
-
double2_with_exact_match =
|
37
|
+
double2_with_exact_match = Double.new(@double_injection)
|
38
38
|
double2_with_exact_match.with(:exact_match_2).returns {:return_2}
|
39
39
|
|
40
40
|
@object.foobar(:exact_match_1).should == :return_1
|
@@ -42,9 +42,9 @@ module RR
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "dispatches to Double that have a wildcard match" do
|
45
|
-
double_with_wildcard_match =
|
45
|
+
double_with_wildcard_match = Double.new(@double_injection)
|
46
46
|
double_with_wildcard_match.with_any_args.returns {:wild_card_value}
|
47
|
-
double_with_no_match =
|
47
|
+
double_with_no_match = Double.new(@double_injection)
|
48
48
|
double_with_no_match.with("nothing that matches").returns {:no_match}
|
49
49
|
|
50
50
|
@object.foobar(:wildcard_match_1).should == :wild_card_value
|
@@ -54,10 +54,10 @@ module RR
|
|
54
54
|
|
55
55
|
describe "where there are doubles" do
|
56
56
|
it "raises DoubleNotFoundError error when arguments do not match a double" do
|
57
|
-
double_1 =
|
57
|
+
double_1 = Double.new(@double_injection)
|
58
58
|
double_1.with(1, 2)
|
59
59
|
|
60
|
-
double_2 =
|
60
|
+
double_2 = Double.new(@double_injection)
|
61
61
|
double_2.with(3)
|
62
62
|
|
63
63
|
error = nil
|
@@ -109,7 +109,7 @@ module RR
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def double(*arguments, &return_value)
|
112
|
-
double =
|
112
|
+
double = Double.new(@double_injection)
|
113
113
|
double.with(*arguments).any_number_of_times.returns(&return_value)
|
114
114
|
double.should_not be_terminal
|
115
115
|
double
|
@@ -145,13 +145,13 @@ module RR
|
|
145
145
|
|
146
146
|
@object.foobar(:exact_match)
|
147
147
|
@object.foobar(:exact_match)
|
148
|
-
|
148
|
+
lambda do
|
149
149
|
@object.foobar(:exact_match)
|
150
150
|
end.should raise_error(Errors::TimesCalledError)
|
151
151
|
end
|
152
152
|
|
153
153
|
def double(*arguments, &return_value)
|
154
|
-
double =
|
154
|
+
double = Double.new(@double_injection)
|
155
155
|
double.with(*arguments).once.returns(&return_value)
|
156
156
|
double.should be_terminal
|
157
157
|
double
|
@@ -187,13 +187,13 @@ module RR
|
|
187
187
|
|
188
188
|
@object.foobar(:anything)
|
189
189
|
@object.foobar(:anything)
|
190
|
-
|
190
|
+
lambda do
|
191
191
|
@object.foobar(:anything)
|
192
192
|
end.should raise_error(Errors::TimesCalledError)
|
193
193
|
end
|
194
194
|
|
195
195
|
def double(&return_value)
|
196
|
-
double =
|
196
|
+
double = Double.new(@double_injection)
|
197
197
|
double.with_any_args.once.returns(&return_value)
|
198
198
|
double.should be_terminal
|
199
199
|
double
|
@@ -207,7 +207,7 @@ module RR
|
|
207
207
|
end
|
208
208
|
|
209
209
|
it "executes the block" do
|
210
|
-
double =
|
210
|
+
double = Double.new(@double_injection)
|
211
211
|
double.with(1, 2) {:return_value}
|
212
212
|
@object.foobar!(1, 2).should == :return_value
|
213
213
|
end
|
@@ -219,7 +219,7 @@ module RR
|
|
219
219
|
end
|
220
220
|
|
221
221
|
it "executes the block" do
|
222
|
-
double =
|
222
|
+
double = Double.new(@double_injection)
|
223
223
|
double.with(1, 2) {:return_value}
|
224
224
|
@object.foobar?(1, 2).should == :return_value
|
225
225
|
end
|
@@ -2,8 +2,9 @@ require "spec/spec_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
describe DoubleInjection, "#verify" do
|
5
|
+
it_should_behave_like "Swapped Space"
|
5
6
|
before do
|
6
|
-
@space = Space.
|
7
|
+
@space = Space.instance
|
7
8
|
@object = Object.new
|
8
9
|
@method_name = :foobar
|
9
10
|
@object.methods.should_not include(@method_name.to_s)
|
@@ -11,13 +12,13 @@ module RR
|
|
11
12
|
end
|
12
13
|
|
13
14
|
it "verifies each double was met" do
|
14
|
-
double = Double.new(@
|
15
|
+
double = Double.new(@double_injection, DoubleDefinition.new)
|
15
16
|
@double_injection.register_double double
|
16
17
|
|
17
18
|
double.with(1).once.returns {nil}
|
18
|
-
|
19
|
+
lambda {@double_injection.verify}.should raise_error(Errors::TimesCalledError)
|
19
20
|
@object.foobar(1)
|
20
|
-
|
21
|
+
lambda {@double_injection.verify}.should_not raise_error
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe
|
4
|
+
describe DoubleDefinitionCreatorProxy, "initializes proxy with passed in creator", :shared => true do
|
5
5
|
it "initializes proxy with passed in creator" do
|
6
6
|
class << the_proxy
|
7
7
|
attr_reader :creator
|
@@ -10,23 +10,25 @@ module RR
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe DoubleDefinitionCreatorProxy do
|
14
14
|
attr_reader :space, :subject, :creator, :the_proxy
|
15
|
+
it_should_behave_like "Swapped Space"
|
16
|
+
|
15
17
|
before(:each) do
|
16
|
-
@space = Space.
|
18
|
+
@space = Space.instance
|
17
19
|
@subject = Object.new
|
18
|
-
@creator =
|
20
|
+
@creator = DoubleDefinitionCreator.new
|
19
21
|
creator.mock
|
20
22
|
end
|
21
23
|
|
22
24
|
describe ".new without block" do
|
23
|
-
it_should_behave_like "RR::
|
25
|
+
it_should_behave_like "RR::DoubleDefinitionCreatorProxy initializes proxy with passed in creator"
|
24
26
|
before do
|
25
|
-
@the_proxy =
|
27
|
+
@the_proxy = DoubleDefinitionCreatorProxy.new(creator, subject)
|
26
28
|
end
|
27
29
|
|
28
30
|
it "clears out all methods from proxy" do
|
29
|
-
proxy_subclass = Class.new(
|
31
|
+
proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
|
30
32
|
def i_should_be_a_double
|
31
33
|
end
|
32
34
|
end
|
@@ -38,9 +40,9 @@ module RR
|
|
38
40
|
end
|
39
41
|
|
40
42
|
describe ".new with block" do
|
41
|
-
it_should_behave_like "RR::
|
43
|
+
it_should_behave_like "RR::DoubleDefinitionCreatorProxy initializes proxy with passed in creator"
|
42
44
|
before do
|
43
|
-
@the_proxy =
|
45
|
+
@the_proxy = DoubleDefinitionCreatorProxy.new(creator, subject) do |b|
|
44
46
|
b.foobar(1, 2) {:one_two}
|
45
47
|
b.foobar(1) {:one}
|
46
48
|
b.foobar.with_any_args {:default}
|
@@ -56,7 +58,7 @@ module RR
|
|
56
58
|
end
|
57
59
|
|
58
60
|
it "clears out all methods from proxy" do
|
59
|
-
proxy_subclass = Class.new(
|
61
|
+
proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
|
60
62
|
def i_should_be_a_double
|
61
63
|
end
|
62
64
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe
|
4
|
+
describe DoubleDefinitionCreator, " strategy definition", :shared => true do
|
5
5
|
it "returns self when passing no args" do
|
6
6
|
creator.__send__(method_name).should === creator
|
7
7
|
end
|
8
8
|
|
9
|
-
it "returns a
|
9
|
+
it "returns a DoubleDefinitionCreatorProxy when passed a subject" do
|
10
10
|
double = creator.__send__(method_name, subject).foobar
|
11
11
|
double.should be_instance_of(DoubleDefinition)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "returns a
|
14
|
+
it "returns a DoubleDefinitionCreatorProxy when passed Kernel" do
|
15
15
|
double = creator.__send__(method_name, Kernel).foobar
|
16
16
|
double.should be_instance_of(DoubleDefinition)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "raises error if passed a method name and a block" do
|
20
|
-
|
20
|
+
lambda do
|
21
21
|
creator.__send__(method_name, subject, :foobar) {}
|
22
22
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "raises error when using mock strategy" do
|
26
26
|
creator.mock
|
27
|
-
|
27
|
+
lambda do
|
28
28
|
creator.__send__(method_name)
|
29
29
|
end.should raise_error(
|
30
30
|
Errors::DoubleDefinitionError,
|
@@ -34,7 +34,7 @@ module RR
|
|
34
34
|
|
35
35
|
it "raises error when using stub strategy" do
|
36
36
|
creator.stub
|
37
|
-
|
37
|
+
lambda do
|
38
38
|
creator.__send__(method_name)
|
39
39
|
end.should raise_error(
|
40
40
|
Errors::DoubleDefinitionError,
|
@@ -44,25 +44,26 @@ module RR
|
|
44
44
|
|
45
45
|
it "raises error when using dont_allow strategy" do
|
46
46
|
creator.dont_allow
|
47
|
-
|
47
|
+
lambda do
|
48
48
|
creator.__send__(method_name)
|
49
49
|
end.should raise_error(
|
50
|
-
|
51
|
-
|
50
|
+
Errors::DoubleDefinitionError,
|
51
|
+
"This Double already has a dont_allow strategy"
|
52
52
|
)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
56
|
+
describe DoubleDefinitionCreator do
|
57
57
|
attr_reader :creator, :subject, :space, :method_name
|
58
|
+
it_should_behave_like "Swapped Space"
|
58
59
|
before(:each) do
|
59
|
-
@space = Space.
|
60
|
+
@space = Space.instance
|
60
61
|
@subject = Object.new
|
61
|
-
@creator =
|
62
|
+
@creator = DoubleDefinitionCreator.new
|
62
63
|
end
|
63
64
|
|
64
65
|
describe "#mock" do
|
65
|
-
it_should_behave_like "RR::
|
66
|
+
it_should_behave_like "RR::DoubleDefinitionCreator strategy definition"
|
66
67
|
|
67
68
|
before do
|
68
69
|
@method_name = :mock
|
@@ -72,19 +73,13 @@ module RR
|
|
72
73
|
creates_mock_call_chain(creator.mock(subject))
|
73
74
|
end
|
74
75
|
|
75
|
-
it "creates a mock Double for method when passed a second argument with rr_mock" do
|
76
|
-
creates_double_with_method_name(
|
77
|
-
creator.mock(subject, :foobar)
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
76
|
it "sets up the DoubleDefinition to be in returns block_callback_strategy" do
|
82
77
|
double = creator.mock(subject, :foobar)
|
83
78
|
double.block_callback_strategy.should == :returns
|
84
79
|
end
|
85
80
|
|
86
|
-
def
|
87
|
-
double.
|
81
|
+
def creates_mock_call_chain(creator)
|
82
|
+
double = creator.foobar(1, 2) {:baz}
|
88
83
|
double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
|
89
84
|
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
90
85
|
double.argument_expectation.expected_arguments.should == [1, 2]
|
@@ -92,18 +87,32 @@ module RR
|
|
92
87
|
subject.foobar(1, 2).should == :baz
|
93
88
|
end
|
94
89
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
double.argument_expectation.expected_arguments.should == [1, 2]
|
90
|
+
context "when passed a second argument" do
|
91
|
+
it "creates a mock Double for method" do
|
92
|
+
creates_double_with_method_name( creator.mock(subject, :foobar) )
|
93
|
+
end
|
100
94
|
|
101
|
-
|
95
|
+
def creates_double_with_method_name(double)
|
96
|
+
double.with(1, 2) {:baz}
|
97
|
+
double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
|
98
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
99
|
+
double.argument_expectation.expected_arguments.should == [1, 2]
|
100
|
+
|
101
|
+
subject.foobar(1, 2).should == :baz
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when passed method_name and block" do
|
106
|
+
it "raises error" do
|
107
|
+
lambda do
|
108
|
+
@creator.mock(@object, :foobar) {}
|
109
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
110
|
+
end
|
102
111
|
end
|
103
112
|
end
|
104
113
|
|
105
114
|
describe "#stub" do
|
106
|
-
it_should_behave_like "RR::
|
115
|
+
it_should_behave_like "RR::DoubleDefinitionCreator strategy definition"
|
107
116
|
|
108
117
|
before do
|
109
118
|
@method_name = :stub
|
@@ -113,20 +122,22 @@ module RR
|
|
113
122
|
creates_stub_call_chain(creator.stub(subject))
|
114
123
|
end
|
115
124
|
|
116
|
-
it "creates a stub Double for method when passed a second argument" do
|
117
|
-
creates_double_with_method_name(creator.stub(subject, :foobar))
|
118
|
-
end
|
119
|
-
|
120
125
|
it "sets up the DoubleDefinition to be in returns block_callback_strategy" do
|
121
126
|
double = creator.stub(subject, :foobar)
|
122
127
|
double.block_callback_strategy.should == :returns
|
123
128
|
end
|
124
129
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
+
context "when passed a second argument" do
|
131
|
+
it "creates a stub Double for method when passed a second argument" do
|
132
|
+
creates_double_with_method_name(creator.stub(subject, :foobar))
|
133
|
+
end
|
134
|
+
|
135
|
+
def creates_double_with_method_name(double)
|
136
|
+
double.with(1, 2) {:baz}
|
137
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
138
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
139
|
+
subject.foobar(1, 2).should == :baz
|
140
|
+
end
|
130
141
|
end
|
131
142
|
|
132
143
|
def creates_stub_call_chain(creator)
|
@@ -135,10 +146,18 @@ module RR
|
|
135
146
|
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
136
147
|
subject.foobar(1, 2).should == :baz
|
137
148
|
end
|
149
|
+
|
150
|
+
context "when passed method_name and block" do
|
151
|
+
it "raises error" do
|
152
|
+
lambda do
|
153
|
+
@creator.stub(@object, :foobar) {}
|
154
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
155
|
+
end
|
156
|
+
end
|
138
157
|
end
|
139
158
|
|
140
159
|
describe "#dont_allow" do
|
141
|
-
it_should_behave_like "RR::
|
160
|
+
it_should_behave_like "RR::DoubleDefinitionCreator strategy definition"
|
142
161
|
|
143
162
|
before do
|
144
163
|
@method_name = :dont_allow
|
@@ -146,7 +165,7 @@ module RR
|
|
146
165
|
|
147
166
|
it "raises error when proxied" do
|
148
167
|
creator.proxy
|
149
|
-
|
168
|
+
lambda do
|
150
169
|
creator.dont_allow
|
151
170
|
end.should raise_error(
|
152
171
|
Errors::DoubleDefinitionError,
|
@@ -170,33 +189,35 @@ module RR
|
|
170
189
|
creates_dont_allow_call_chain(creator.dont_allow(subject))
|
171
190
|
end
|
172
191
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
it "creates a mock Double for method when passed a second argument" do
|
178
|
-
creates_double_with_method_name(creator.dont_call(subject, :foobar))
|
179
|
-
end
|
192
|
+
context "when passed a second argument_expectation" do
|
193
|
+
it "creates a mock Double for method" do
|
194
|
+
creates_double_with_method_name(creator.dont_allow(subject, :foobar))
|
195
|
+
end
|
180
196
|
|
181
|
-
|
182
|
-
|
183
|
-
|
197
|
+
it "creates a mock Double for method" do
|
198
|
+
creates_double_with_method_name(creator.dont_call(subject, :foobar))
|
199
|
+
end
|
184
200
|
|
185
|
-
|
186
|
-
|
187
|
-
|
201
|
+
it "creates a mock Double for method" do
|
202
|
+
creates_double_with_method_name(creator.do_not_allow(subject, :foobar))
|
203
|
+
end
|
188
204
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
193
|
-
double.argument_expectation.expected_arguments.should == [1, 2]
|
205
|
+
it "creates a mock Double for method" do
|
206
|
+
creates_double_with_method_name(creator.dont_allow(subject, :foobar))
|
207
|
+
end
|
194
208
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
209
|
+
def creates_double_with_method_name(double)
|
210
|
+
double.with(1, 2)
|
211
|
+
double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
|
212
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
213
|
+
double.argument_expectation.expected_arguments.should == [1, 2]
|
214
|
+
|
215
|
+
lambda do
|
216
|
+
subject.foobar(1, 2)
|
217
|
+
end.should raise_error(Errors::TimesCalledError)
|
218
|
+
reset
|
219
|
+
nil
|
220
|
+
end
|
200
221
|
end
|
201
222
|
|
202
223
|
def creates_dont_allow_call_chain(creator)
|
@@ -205,12 +226,20 @@ module RR
|
|
205
226
|
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
206
227
|
double.argument_expectation.expected_arguments.should == [1, 2]
|
207
228
|
|
208
|
-
|
229
|
+
lambda do
|
209
230
|
subject.foobar(1, 2)
|
210
231
|
end.should raise_error(Errors::TimesCalledError)
|
211
232
|
reset
|
212
233
|
nil
|
213
234
|
end
|
235
|
+
|
236
|
+
context "when passed method_name and block" do
|
237
|
+
it "raises error" do
|
238
|
+
lambda do
|
239
|
+
@creator.dont_allow(@object, :foobar) {}
|
240
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
241
|
+
end
|
242
|
+
end
|
214
243
|
end
|
215
244
|
|
216
245
|
describe "(#proxy or #proxy) and #stub" do
|
@@ -224,7 +253,7 @@ module RR
|
|
224
253
|
|
225
254
|
it "raises error when using dont_allow strategy" do
|
226
255
|
creator.dont_allow
|
227
|
-
|
256
|
+
lambda do
|
228
257
|
creator.proxy
|
229
258
|
end.should raise_error(
|
230
259
|
Errors::DoubleDefinitionError,
|
@@ -246,20 +275,22 @@ module RR
|
|
246
275
|
subject.foobar(1, 2).should == :baz
|
247
276
|
end
|
248
277
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
278
|
+
context "when passed a second argument" do
|
279
|
+
it "creates a proxy Double for method" do
|
280
|
+
double = creator.stub.proxy(subject, :foobar)
|
281
|
+
double.with(1, 2) {:baz}
|
282
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
283
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
284
|
+
subject.foobar(1, 2).should == :baz
|
285
|
+
end
|
256
286
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
287
|
+
it "creates a proxy Double for method" do
|
288
|
+
double = creator.stub.proxy(subject, :foobar)
|
289
|
+
double.with(1, 2) {:baz}
|
290
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
291
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
292
|
+
subject.foobar(1, 2).should == :baz
|
293
|
+
end
|
263
294
|
end
|
264
295
|
|
265
296
|
it "sets up the DoubleDefinition to be in after_call block_callback_strategy" do
|
@@ -275,11 +306,19 @@ module RR
|
|
275
306
|
args.should == [:original_implementation_value]
|
276
307
|
double.block_callback_strategy.should == :after_call
|
277
308
|
end
|
309
|
+
|
310
|
+
context "when passed method_name and block" do
|
311
|
+
it "raises error" do
|
312
|
+
lambda do
|
313
|
+
@creator.proxy(@object, :foobar) {}
|
314
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
315
|
+
end
|
316
|
+
end
|
278
317
|
end
|
279
318
|
|
280
319
|
describe "#instance_of" do
|
281
320
|
it "raises an error when not passed a class" do
|
282
|
-
|
321
|
+
lambda do
|
283
322
|
creator.instance_of(Object.new)
|
284
323
|
end.should raise_error(ArgumentError, "instance_of only accepts class objects")
|
285
324
|
end
|
@@ -292,20 +331,29 @@ module RR
|
|
292
331
|
klass.new.foobar(1, 2).should == :baz
|
293
332
|
end
|
294
333
|
|
295
|
-
|
334
|
+
context "when passed a second argument" do
|
335
|
+
it "creates a proxy Double for method" do
|
336
|
+
klass = Class.new
|
337
|
+
double = creator.stub.instance_of(klass, :foobar)
|
338
|
+
double.with(1, 2) {:baz}
|
339
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
340
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
341
|
+
klass.new.foobar(1, 2).should == :baz
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
it "raises error" do
|
296
346
|
klass = Class.new
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
301
|
-
klass.new.foobar(1, 2).should == :baz
|
347
|
+
lambda do
|
348
|
+
@creator.instance_of(klass, :foobar) {}
|
349
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
302
350
|
end
|
303
351
|
end
|
304
352
|
|
305
|
-
describe "#create
|
353
|
+
describe "#create using no strategy" do
|
306
354
|
it "raises error" do
|
307
|
-
|
308
|
-
creator.create
|
355
|
+
lambda do
|
356
|
+
creator.create(subject, :foobar, 1, 2)
|
309
357
|
end.should raise_error(
|
310
358
|
Errors::DoubleDefinitionError,
|
311
359
|
"This Double has no strategy"
|
@@ -313,65 +361,65 @@ module RR
|
|
313
361
|
end
|
314
362
|
end
|
315
363
|
|
316
|
-
describe "#create
|
364
|
+
describe "#create using mock strategy" do
|
317
365
|
before do
|
318
366
|
creator.mock
|
319
367
|
end
|
320
368
|
|
321
369
|
it "sets expectations on the subject" do
|
322
|
-
creator.create
|
370
|
+
creator.create(subject, :foobar, 1, 2) {:baz}.twice
|
323
371
|
|
324
372
|
subject.foobar(1, 2).should == :baz
|
325
373
|
subject.foobar(1, 2).should == :baz
|
326
|
-
|
374
|
+
lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
327
375
|
end
|
328
376
|
end
|
329
377
|
|
330
|
-
describe "#create
|
378
|
+
describe "#create using stub strategy" do
|
331
379
|
before do
|
332
380
|
creator.stub
|
333
381
|
end
|
334
382
|
|
335
383
|
it "stubs the subject without any args" do
|
336
|
-
creator.create
|
384
|
+
creator.create(subject, :foobar) {:baz}
|
337
385
|
subject.foobar.should == :baz
|
338
386
|
end
|
339
387
|
|
340
388
|
it "stubs the subject mapping passed in args with the output" do
|
341
|
-
creator.create
|
342
|
-
creator.create
|
343
|
-
creator.create
|
389
|
+
creator.create(subject, :foobar, 1, 2) {:one_two}
|
390
|
+
creator.create(subject, :foobar, 1) {:one}
|
391
|
+
creator.create(subject, :foobar) {:nothing}
|
344
392
|
subject.foobar.should == :nothing
|
345
393
|
subject.foobar(1).should == :one
|
346
394
|
subject.foobar(1, 2).should == :one_two
|
347
395
|
end
|
348
396
|
end
|
349
397
|
|
350
|
-
describe "#create
|
398
|
+
describe "#create using dont_allow strategy" do
|
351
399
|
before do
|
352
400
|
creator.dont_allow
|
353
401
|
end
|
354
402
|
|
355
403
|
it "sets expectation for method to never be called with any arguments when on arguments passed in" do
|
356
|
-
creator.create
|
357
|
-
|
358
|
-
|
404
|
+
creator.create(subject, :foobar)
|
405
|
+
lambda {subject.foobar}.should raise_error(Errors::TimesCalledError)
|
406
|
+
lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
359
407
|
end
|
360
408
|
|
361
409
|
it "sets expectation for method to never be called with passed in arguments" do
|
362
|
-
creator.create
|
363
|
-
|
364
|
-
|
410
|
+
creator.create(subject, :foobar, 1, 2)
|
411
|
+
lambda {subject.foobar}.should raise_error(Errors::DoubleNotFoundError)
|
412
|
+
lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
365
413
|
end
|
366
414
|
|
367
415
|
it "sets expectation for method to never be called with no arguments when with_no_args is set" do
|
368
|
-
creator.create
|
369
|
-
|
370
|
-
|
416
|
+
creator.create(subject, :foobar).with_no_args
|
417
|
+
lambda {subject.foobar}.should raise_error(Errors::TimesCalledError)
|
418
|
+
lambda {subject.foobar(1, 2)}.should raise_error(Errors::DoubleNotFoundError)
|
371
419
|
end
|
372
420
|
end
|
373
421
|
|
374
|
-
describe "#create
|
422
|
+
describe "#create using mock strategy with proxy" do
|
375
423
|
before do
|
376
424
|
creator.mock
|
377
425
|
creator.proxy
|
@@ -381,21 +429,18 @@ module RR
|
|
381
429
|
def subject.foobar(*args)
|
382
430
|
; :baz;
|
383
431
|
end
|
384
|
-
creator.create
|
432
|
+
creator.create(subject, :foobar, 1, 2).twice
|
385
433
|
subject.foobar(1, 2).should == :baz
|
386
434
|
subject.foobar(1, 2).should == :baz
|
387
|
-
|
435
|
+
lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
388
436
|
end
|
389
437
|
|
390
438
|
it "sets after_call on the double when passed a block" do
|
391
439
|
real_value = Object.new
|
392
|
-
(
|
393
|
-
class << subject;
|
394
|
-
self;
|
395
|
-
end).class_eval do
|
440
|
+
(class << subject; self; end).class_eval do
|
396
441
|
define_method(:foobar) {real_value}
|
397
442
|
end
|
398
|
-
creator.create
|
443
|
+
creator.create(subject, :foobar, 1, 2) do |value|
|
399
444
|
mock(value).a_method {99}
|
400
445
|
value
|
401
446
|
end
|
@@ -406,7 +451,7 @@ module RR
|
|
406
451
|
end
|
407
452
|
end
|
408
453
|
|
409
|
-
describe "#create
|
454
|
+
describe "#create using stub strategy with proxy" do
|
410
455
|
before do
|
411
456
|
creator.stub
|
412
457
|
creator.proxy
|
@@ -414,19 +459,19 @@ module RR
|
|
414
459
|
|
415
460
|
it "sets up a double with passed in arguments" do
|
416
461
|
def subject.foobar(*args)
|
417
|
-
|
462
|
+
:baz
|
418
463
|
end
|
419
|
-
creator.create
|
420
|
-
|
464
|
+
creator.create(subject, :foobar, 1, 2)
|
465
|
+
lambda do
|
421
466
|
subject.foobar
|
422
467
|
end.should raise_error(Errors::DoubleNotFoundError)
|
423
468
|
end
|
424
469
|
|
425
470
|
it "sets expectations on the subject while calling the original method" do
|
426
471
|
def subject.foobar(*args)
|
427
|
-
|
472
|
+
:baz
|
428
473
|
end
|
429
|
-
creator.create
|
474
|
+
creator.create(subject, :foobar, 1, 2) {:new_value}
|
430
475
|
10.times do
|
431
476
|
subject.foobar(1, 2).should == :new_value
|
432
477
|
end
|
@@ -434,13 +479,10 @@ module RR
|
|
434
479
|
|
435
480
|
it "sets after_call on the double when passed a block" do
|
436
481
|
real_value = Object.new
|
437
|
-
(
|
438
|
-
class << subject;
|
439
|
-
self;
|
440
|
-
end).class_eval do
|
482
|
+
(class << subject; self; end).class_eval do
|
441
483
|
define_method(:foobar) {real_value}
|
442
484
|
end
|
443
|
-
creator.create
|
485
|
+
creator.create(subject, :foobar, 1, 2) do |value|
|
444
486
|
mock(value).a_method {99}
|
445
487
|
value
|
446
488
|
end
|