rr 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/README +13 -0
- data/Rakefile +1 -1
- data/lib/rr.rb +3 -3
- data/lib/rr/adapters/rr_methods.rb +5 -5
- data/lib/rr/double.rb +5 -5
- data/lib/rr/double_creator.rb +13 -13
- data/lib/rr/double_definition.rb +3 -3
- data/lib/rr/double_injection.rb +24 -24
- data/lib/rr/double_matches.rb +29 -29
- data/lib/rr/errors/{scenario_definition_error.rb → double_definition_error.rb} +0 -0
- data/lib/rr/errors/{scenario_not_found_error.rb → double_not_found_error.rb} +0 -0
- data/lib/rr/errors/{scenario_order_error.rb → double_order_error.rb} +0 -0
- data/lib/rr/expectations/times_called_expectation.rb +4 -4
- data/lib/rr/space.rb +22 -22
- data/spec/rr/adapters/rr_methods_creator_spec.rb +69 -69
- data/spec/rr/adapters/rr_methods_space_spec.rb +11 -11
- data/spec/rr/double/double_injection_dispatching_spec.rb +66 -66
- data/spec/rr/double/double_injection_register_scenario_spec.rb +8 -8
- data/spec/rr/double/double_injection_verify_spec.rb +4 -4
- data/spec/rr/double_creator_spec.rb +65 -65
- data/spec/rr/double_definition_spec.rb +9 -9
- data/spec/rr/double_method_proxy_spec.rb +7 -7
- data/spec/rr/double_spec.rb +199 -199
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +1 -1
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +1 -1
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +1 -1
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +3 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +1 -1
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +1 -1
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +1 -1
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +4 -4
- data/spec/rr/rspec/rspec_adapter_spec.rb +2 -2
- data/spec/rr/space/space_create_spec.rb +37 -37
- data/spec/rr/space/space_register_spec.rb +9 -9
- data/spec/rr/space/space_reset_spec.rb +7 -7
- data/spec/rr/space/space_verify_spec.rb +31 -31
- metadata +5 -5
@@ -1,24 +1,24 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe DoubleInjection, "#
|
4
|
+
describe DoubleInjection, "#register_double" do
|
5
5
|
before do
|
6
6
|
@space = Space.new
|
7
7
|
@object = Object.new
|
8
8
|
@method_name = :foobar
|
9
9
|
@object.methods.should_not include(@method_name.to_s)
|
10
10
|
@double_insertion = DoubleInjection.new(@space, @object, @method_name)
|
11
|
-
def @double_insertion.
|
12
|
-
@
|
11
|
+
def @double_insertion.doubles
|
12
|
+
@doubles
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
it "adds the
|
17
|
-
|
16
|
+
it "adds the double to the doubles list" do
|
17
|
+
double = Double.new(@space, @double_insertion, @space.double_definition)
|
18
18
|
|
19
|
-
@double_insertion.
|
20
|
-
@double_insertion.
|
21
|
-
@double_insertion.
|
19
|
+
@double_insertion.doubles.should_not include(double)
|
20
|
+
@double_insertion.register_double double
|
21
|
+
@double_insertion.doubles.should include(double)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -10,11 +10,11 @@ module RR
|
|
10
10
|
@double_insertion = @space.double_insertion(@object, @method_name)
|
11
11
|
end
|
12
12
|
|
13
|
-
it "verifies each
|
14
|
-
|
15
|
-
@double_insertion.
|
13
|
+
it "verifies each double was met" do
|
14
|
+
double = Double.new(@space, @double_insertion, @space.double_definition)
|
15
|
+
@double_insertion.register_double double
|
16
16
|
|
17
|
-
|
17
|
+
double.with(1).once.returns {nil}
|
18
18
|
proc {@double_insertion.verify}.should raise_error(Errors::TimesCalledError)
|
19
19
|
@object.foobar(1)
|
20
20
|
proc {@double_insertion.verify}.should_not raise_error
|
@@ -7,13 +7,13 @@ module RR
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns a DoubleMethodProxy when passed a subject" do
|
10
|
-
|
11
|
-
|
10
|
+
double = creator.__send__(method_name, subject).foobar
|
11
|
+
double.should be_instance_of(DoubleDefinition)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns a DoubleMethodProxy when passed Kernel" do
|
15
|
-
|
16
|
-
|
15
|
+
double = creator.__send__(method_name, Kernel).foobar
|
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
|
@@ -73,30 +73,30 @@ module RR
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "creates a mock Double for method when passed a second argument with rr_mock" do
|
76
|
-
|
76
|
+
creates_double_with_method_name(
|
77
77
|
creator.mock(subject, :foobar)
|
78
78
|
)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "sets up the DoubleDefinition to be in returns block_callback_strategy" do
|
82
|
-
|
83
|
-
|
82
|
+
double = creator.mock(subject, :foobar)
|
83
|
+
double.block_callback_strategy.should == :returns
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
def creates_double_with_method_name(double)
|
87
|
+
double.with(1, 2) {:baz}
|
88
|
+
double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
|
89
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
90
|
+
double.argument_expectation.expected_arguments.should == [1, 2]
|
91
91
|
|
92
92
|
subject.foobar(1, 2).should == :baz
|
93
93
|
end
|
94
94
|
|
95
95
|
def creates_mock_call_chain(creator)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
double = creator.foobar(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
100
|
|
101
101
|
subject.foobar(1, 2).should == :baz
|
102
102
|
end
|
@@ -114,25 +114,25 @@ module RR
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "creates a stub Double for method when passed a second argument" do
|
117
|
-
|
117
|
+
creates_double_with_method_name(creator.stub(subject, :foobar))
|
118
118
|
end
|
119
119
|
|
120
120
|
it "sets up the DoubleDefinition to be in returns block_callback_strategy" do
|
121
|
-
|
122
|
-
|
121
|
+
double = creator.stub(subject, :foobar)
|
122
|
+
double.block_callback_strategy.should == :returns
|
123
123
|
end
|
124
124
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
def creates_double_with_method_name(double)
|
126
|
+
double.with(1, 2) {:baz}
|
127
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
128
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
129
129
|
subject.foobar(1, 2).should == :baz
|
130
130
|
end
|
131
131
|
|
132
132
|
def creates_stub_call_chain(creator)
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
double = creator.foobar(1, 2) {:baz}
|
134
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
135
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
136
136
|
subject.foobar(1, 2).should == :baz
|
137
137
|
end
|
138
138
|
end
|
@@ -171,26 +171,26 @@ module RR
|
|
171
171
|
end
|
172
172
|
|
173
173
|
it "creates a mock Double for method when passed a second argument" do
|
174
|
-
|
174
|
+
creates_double_with_method_name(creator.dont_allow(subject, :foobar))
|
175
175
|
end
|
176
176
|
|
177
177
|
it "creates a mock Double for method when passed a second argument" do
|
178
|
-
|
178
|
+
creates_double_with_method_name(creator.dont_call(subject, :foobar))
|
179
179
|
end
|
180
180
|
|
181
181
|
it "creates a mock Double for method when passed a second argument" do
|
182
|
-
|
182
|
+
creates_double_with_method_name(creator.do_not_allow(subject, :foobar))
|
183
183
|
end
|
184
184
|
|
185
185
|
it "creates a mock Double for method when passed a second argument" do
|
186
|
-
|
186
|
+
creates_double_with_method_name(creator.dont_allow(subject, :foobar))
|
187
187
|
end
|
188
188
|
|
189
|
-
def
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
189
|
+
def creates_double_with_method_name(double)
|
190
|
+
double.with(1, 2)
|
191
|
+
double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
|
192
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
193
|
+
double.argument_expectation.expected_arguments.should == [1, 2]
|
194
194
|
|
195
195
|
proc do
|
196
196
|
subject.foobar(1, 2)
|
@@ -200,10 +200,10 @@ module RR
|
|
200
200
|
end
|
201
201
|
|
202
202
|
def creates_dont_allow_call_chain(creator)
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
203
|
+
double = creator.foobar(1, 2)
|
204
|
+
double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
|
205
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
206
|
+
double.argument_expectation.expected_arguments.should == [1, 2]
|
207
207
|
|
208
208
|
proc do
|
209
209
|
subject.foobar(1, 2)
|
@@ -233,32 +233,32 @@ module RR
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "sets up the RR proxy call chain" do
|
236
|
-
|
237
|
-
|
238
|
-
|
236
|
+
double = creator.stub.proxy(subject).foobar(1, 2) {:baz}
|
237
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
238
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
239
239
|
subject.foobar(1, 2).should == :baz
|
240
240
|
end
|
241
241
|
|
242
242
|
it "sets up the RR proxy call chain" do
|
243
|
-
|
244
|
-
|
245
|
-
|
243
|
+
double = creator.stub.proxy(subject).foobar(1, 2) {:baz}
|
244
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
245
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
246
246
|
subject.foobar(1, 2).should == :baz
|
247
247
|
end
|
248
248
|
|
249
249
|
it "creates a proxy Double for method when passed a second argument" do
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
250
|
+
double = creator.stub.proxy(subject, :foobar)
|
251
|
+
double.with(1, 2) {:baz}
|
252
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
253
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
254
254
|
subject.foobar(1, 2).should == :baz
|
255
255
|
end
|
256
256
|
|
257
257
|
it "creates a proxy Double for method when passed a second argument" do
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
258
|
+
double = creator.stub.proxy(subject, :foobar)
|
259
|
+
double.with(1, 2) {:baz}
|
260
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
261
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
262
262
|
subject.foobar(1, 2).should == :baz
|
263
263
|
end
|
264
264
|
|
@@ -268,12 +268,12 @@ module RR
|
|
268
268
|
end
|
269
269
|
|
270
270
|
args = nil
|
271
|
-
|
271
|
+
double = creator.stub.proxy(subject, :foobar).with() do |*args|
|
272
272
|
args = args
|
273
273
|
end
|
274
274
|
subject.foobar
|
275
275
|
args.should == [:original_implementation_value]
|
276
|
-
|
276
|
+
double.block_callback_strategy.should == :after_call
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -286,18 +286,18 @@ module RR
|
|
286
286
|
|
287
287
|
it "sets up the RR proxy call chain" do
|
288
288
|
klass = Class.new
|
289
|
-
|
290
|
-
|
291
|
-
|
289
|
+
double = creator.stub.instance_of(klass).foobar(1, 2) {:baz}
|
290
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
291
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
292
292
|
klass.new.foobar(1, 2).should == :baz
|
293
293
|
end
|
294
294
|
|
295
295
|
it "creates a proxy Double for method when passed a second argument" do
|
296
296
|
klass = Class.new
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
297
|
+
double = creator.stub.instance_of(klass, :foobar)
|
298
|
+
double.with(1, 2) {:baz}
|
299
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
300
|
+
double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
301
301
|
klass.new.foobar(1, 2).should == :baz
|
302
302
|
end
|
303
303
|
end
|
@@ -387,7 +387,7 @@ module RR
|
|
387
387
|
proc {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
388
388
|
end
|
389
389
|
|
390
|
-
it "sets after_call on the
|
390
|
+
it "sets after_call on the double when passed a block" do
|
391
391
|
real_value = Object.new
|
392
392
|
(
|
393
393
|
class << subject;
|
@@ -412,7 +412,7 @@ module RR
|
|
412
412
|
creator.proxy
|
413
413
|
end
|
414
414
|
|
415
|
-
it "sets up a
|
415
|
+
it "sets up a double with passed in arguments" do
|
416
416
|
def subject.foobar(*args)
|
417
417
|
; :baz;
|
418
418
|
end
|
@@ -432,7 +432,7 @@ module RR
|
|
432
432
|
end
|
433
433
|
end
|
434
434
|
|
435
|
-
it "sets after_call on the
|
435
|
+
it "sets after_call on the double when passed a block" do
|
436
436
|
real_value = Object.new
|
437
437
|
(
|
438
438
|
class << subject;
|
@@ -7,8 +7,8 @@ describe DoubleDefinition, :shared => true do
|
|
7
7
|
@object = Object.new
|
8
8
|
add_original_method
|
9
9
|
@double_insertion = @space.double_insertion(@object, :foobar)
|
10
|
-
@
|
11
|
-
@definition = @
|
10
|
+
@double = @space.double(@double_insertion)
|
11
|
+
@definition = @double.definition
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_original_method
|
@@ -454,14 +454,14 @@ end
|
|
454
454
|
describe DoubleDefinition, "#ordered", :shared => true do
|
455
455
|
it_should_behave_like "RR::DoubleDefinition"
|
456
456
|
|
457
|
-
it "adds itself to the ordered
|
457
|
+
it "adds itself to the ordered doubles list" do
|
458
458
|
@definition.ordered
|
459
|
-
@space.
|
459
|
+
@space.ordered_doubles.should include(@double)
|
460
460
|
end
|
461
461
|
|
462
462
|
it "does not double_insertion add itself" do
|
463
463
|
@definition.ordered
|
464
|
-
@space.
|
464
|
+
@space.ordered_doubles.should == [@double]
|
465
465
|
end
|
466
466
|
|
467
467
|
it "sets ordered? to true" do
|
@@ -469,7 +469,7 @@ describe DoubleDefinition, "#ordered", :shared => true do
|
|
469
469
|
end
|
470
470
|
|
471
471
|
it "raises error when there is no Double" do
|
472
|
-
@definition.
|
472
|
+
@definition.double = nil
|
473
473
|
proc do
|
474
474
|
@definition.ordered
|
475
475
|
end.should raise_error(
|
@@ -684,9 +684,9 @@ describe DoubleDefinition, "#implemented_by_original_method" do
|
|
684
684
|
end
|
685
685
|
end
|
686
686
|
double_insertion = @space.double_insertion(@object, :does_not_exist)
|
687
|
-
|
688
|
-
|
689
|
-
|
687
|
+
double = @space.double(double_insertion)
|
688
|
+
double.with_any_args
|
689
|
+
double.implemented_by_original_method
|
690
690
|
|
691
691
|
return_value = @object.does_not_exist(1, 2)
|
692
692
|
return_value.should == "method_missing for does_not_exist([1, 2])"
|
@@ -15,7 +15,7 @@ module RR
|
|
15
15
|
before(:each) do
|
16
16
|
@space = Space.new
|
17
17
|
@subject = Object.new
|
18
|
-
@creator = space.
|
18
|
+
@creator = space.double_creator
|
19
19
|
creator.mock
|
20
20
|
end
|
21
21
|
|
@@ -27,13 +27,13 @@ module RR
|
|
27
27
|
|
28
28
|
it "clears out all methods from proxy" do
|
29
29
|
proxy_subclass = Class.new(DoubleMethodProxy) do
|
30
|
-
def
|
30
|
+
def i_should_be_a_double
|
31
31
|
end
|
32
32
|
end
|
33
|
-
proxy_subclass.instance_methods.should include('
|
33
|
+
proxy_subclass.instance_methods.should include('i_should_be_a_double')
|
34
34
|
|
35
35
|
proxy = proxy_subclass.new(space, creator, subject)
|
36
|
-
proxy.
|
36
|
+
proxy.i_should_be_a_double.should be_instance_of(DoubleDefinition)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -57,13 +57,13 @@ module RR
|
|
57
57
|
|
58
58
|
it "clears out all methods from proxy" do
|
59
59
|
proxy_subclass = Class.new(DoubleMethodProxy) do
|
60
|
-
def
|
60
|
+
def i_should_be_a_double
|
61
61
|
end
|
62
62
|
end
|
63
|
-
proxy_subclass.instance_methods.should include('
|
63
|
+
proxy_subclass.instance_methods.should include('i_should_be_a_double')
|
64
64
|
|
65
65
|
proxy_subclass.new(space, creator, subject) do |m|
|
66
|
-
m.
|
66
|
+
m.i_should_be_a_double.should be_instance_of(DoubleDefinition)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/spec/rr/double_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec/spec_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
describe Double do
|
5
|
-
attr_reader :space, :object, :double_insertion, :
|
5
|
+
attr_reader :space, :object, :double_insertion, :double
|
6
6
|
before do
|
7
7
|
@space = Space.new
|
8
8
|
@object = Object.new
|
@@ -10,38 +10,38 @@ module RR
|
|
10
10
|
[b, a]
|
11
11
|
end
|
12
12
|
@double_insertion = space.double_insertion(object, :foobar)
|
13
|
-
@
|
13
|
+
@double = space.double(double_insertion)
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#with" do
|
17
17
|
it "returns DoubleDefinition" do
|
18
|
-
|
18
|
+
double.with(1).should === double.definition
|
19
19
|
end
|
20
20
|
|
21
21
|
it "sets an ArgumentEqualityExpectation" do
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
double.with(1)
|
23
|
+
double.should be_exact_match(1)
|
24
|
+
double.should_not be_exact_match(2)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "sets return value when block passed in" do
|
28
|
-
|
28
|
+
double.with(1) {:return_value}
|
29
29
|
object.foobar(1).should == :return_value
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#with_any_args" do
|
34
34
|
before do
|
35
|
-
|
35
|
+
double.with_any_args {:return_value}
|
36
36
|
end
|
37
37
|
|
38
38
|
it "returns DoubleDefinition" do
|
39
|
-
|
39
|
+
double.with_no_args.should === double.definition
|
40
40
|
end
|
41
41
|
|
42
42
|
it "sets an AnyArgumentExpectation" do
|
43
|
-
|
44
|
-
|
43
|
+
double.should_not be_exact_match(1)
|
44
|
+
double.should be_wildcard_match(1)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "sets return value when block passed in" do
|
@@ -51,15 +51,15 @@ module RR
|
|
51
51
|
|
52
52
|
describe "#with_no_args" do
|
53
53
|
before do
|
54
|
-
|
54
|
+
double.with_no_args {:return_value}
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns DoubleDefinition" do
|
58
|
-
|
58
|
+
double.with_no_args.should === double.definition
|
59
59
|
end
|
60
60
|
|
61
61
|
it "sets an ArgumentEqualityExpectation with no arguments" do
|
62
|
-
|
62
|
+
double.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
|
63
63
|
end
|
64
64
|
|
65
65
|
it "sets return value when block passed in" do
|
@@ -69,82 +69,82 @@ module RR
|
|
69
69
|
|
70
70
|
describe "#never" do
|
71
71
|
it "returns DoubleDefinition" do
|
72
|
-
|
72
|
+
double.never.should === double.definition
|
73
73
|
end
|
74
74
|
|
75
75
|
it "sets up a Times Called Expectation with 0" do
|
76
|
-
|
77
|
-
proc {
|
76
|
+
double.never
|
77
|
+
proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "sets return value when block passed in" do
|
81
|
-
|
82
|
-
proc {
|
81
|
+
double.with_any_args.never
|
82
|
+
proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
describe "#once" do
|
87
87
|
it "returns DoubleDefinition" do
|
88
|
-
|
88
|
+
double.once.should === double.definition
|
89
89
|
end
|
90
90
|
|
91
91
|
it "sets up a Times Called Expectation with 1" do
|
92
|
-
|
93
|
-
|
94
|
-
proc {
|
92
|
+
double.once
|
93
|
+
double.call(double_insertion)
|
94
|
+
proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "sets return value when block passed in" do
|
98
|
-
|
98
|
+
double.with_any_args.once {:return_value}
|
99
99
|
object.foobar.should == :return_value
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "#twice" do
|
104
104
|
it "returns DoubleDefinition" do
|
105
|
-
|
105
|
+
double.twice.should === double.definition
|
106
106
|
end
|
107
107
|
|
108
108
|
it "sets up a Times Called Expectation with 2" do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
proc {
|
109
|
+
double.twice
|
110
|
+
double.call(double_insertion)
|
111
|
+
double.call(double_insertion)
|
112
|
+
proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
|
113
113
|
end
|
114
114
|
|
115
115
|
it "sets return value when block passed in" do
|
116
|
-
|
116
|
+
double.with_any_args.twice {:return_value}
|
117
117
|
object.foobar.should == :return_value
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
describe "#at_least" do
|
122
122
|
it "returns DoubleDefinition" do
|
123
|
-
|
123
|
+
double.with_any_args.at_least(2).should === double.definition
|
124
124
|
end
|
125
125
|
|
126
126
|
it "sets up a AtLeastMatcher with 2" do
|
127
|
-
|
128
|
-
|
127
|
+
double.at_least(2)
|
128
|
+
double.definition.times_matcher.should == TimesCalledMatchers::AtLeastMatcher.new(2)
|
129
129
|
end
|
130
130
|
|
131
131
|
it "sets return value when block passed in" do
|
132
|
-
|
132
|
+
double.with_any_args.at_least(2) {:return_value}
|
133
133
|
object.foobar.should == :return_value
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "#at_most" do
|
138
138
|
it "returns DoubleDefinition" do
|
139
|
-
|
139
|
+
double.with_any_args.at_most(2).should === double.definition
|
140
140
|
end
|
141
141
|
|
142
142
|
it "sets up a Times Called Expectation with 1" do
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
double.at_most(2)
|
144
|
+
double.call(double_insertion)
|
145
|
+
double.call(double_insertion)
|
146
146
|
proc do
|
147
|
-
|
147
|
+
double.call(double_insertion)
|
148
148
|
end.should raise_error(
|
149
149
|
Errors::TimesCalledError,
|
150
150
|
"foobar()\nCalled 3 times.\nExpected at most 2 times."
|
@@ -152,89 +152,89 @@ module RR
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it "sets return value when block passed in" do
|
155
|
-
|
155
|
+
double.with_any_args.at_most(2) {:return_value}
|
156
156
|
object.foobar.should == :return_value
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
160
|
describe "#times" do
|
161
161
|
it "returns DoubleDefinition" do
|
162
|
-
|
162
|
+
double.times(3).should === double.definition
|
163
163
|
end
|
164
164
|
|
165
165
|
it "sets up a Times Called Expectation with passed in times" do
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
proc {
|
166
|
+
double.times(3)
|
167
|
+
double.call(double_insertion)
|
168
|
+
double.call(double_insertion)
|
169
|
+
double.call(double_insertion)
|
170
|
+
proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "sets return value when block passed in" do
|
174
|
-
|
174
|
+
double.with_any_args.times(3) {:return_value}
|
175
175
|
object.foobar.should == :return_value
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
179
|
describe "#any_number_of_times" do
|
180
180
|
it "returns DoubleDefinition" do
|
181
|
-
|
181
|
+
double.any_number_of_times.should === double.definition
|
182
182
|
end
|
183
183
|
|
184
184
|
it "sets up a Times Called Expectation with AnyTimes matcher" do
|
185
|
-
|
186
|
-
|
185
|
+
double.any_number_of_times
|
186
|
+
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
187
187
|
end
|
188
188
|
|
189
189
|
it "sets return value when block passed in" do
|
190
|
-
|
190
|
+
double.with_any_args.any_number_of_times {:return_value}
|
191
191
|
object.foobar.should == :return_value
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
195
|
describe "#ordered" do
|
196
|
-
it "adds itself to the ordered
|
197
|
-
|
198
|
-
space.
|
196
|
+
it "adds itself to the ordered doubles list" do
|
197
|
+
double.ordered
|
198
|
+
space.ordered_doubles.should include(double)
|
199
199
|
end
|
200
200
|
|
201
201
|
it "does not double_insertion add itself" do
|
202
|
-
|
203
|
-
|
204
|
-
space.
|
202
|
+
double.ordered
|
203
|
+
double.ordered
|
204
|
+
space.ordered_doubles.should == [double ]
|
205
205
|
end
|
206
206
|
|
207
207
|
it "sets ordered? to true" do
|
208
|
-
|
209
|
-
|
208
|
+
double.ordered
|
209
|
+
double.should be_ordered
|
210
210
|
end
|
211
211
|
|
212
212
|
it "sets return value when block passed in" do
|
213
|
-
|
213
|
+
double.with_any_args.once.ordered {:return_value}
|
214
214
|
object.foobar.should == :return_value
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
218
|
describe "#ordered?" do
|
219
219
|
it "defaults to false" do
|
220
|
-
|
220
|
+
double.should_not be_ordered
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
224
|
describe "#yields" do
|
225
225
|
it "returns DoubleDefinition" do
|
226
|
-
|
226
|
+
double.yields(:baz).should === double.definition
|
227
227
|
end
|
228
228
|
|
229
229
|
it "yields the passed in argument to the call block when there is no returns value set" do
|
230
|
-
|
230
|
+
double.with_any_args.yields(:baz)
|
231
231
|
passed_in_block_arg = nil
|
232
232
|
object.foobar {|arg| passed_in_block_arg = arg}.should == nil
|
233
233
|
passed_in_block_arg.should == :baz
|
234
234
|
end
|
235
235
|
|
236
236
|
it "yields the passed in argument to the call block when there is a no returns value set" do
|
237
|
-
|
237
|
+
double.with_any_args.yields(:baz).returns(:return_value)
|
238
238
|
|
239
239
|
passed_in_block_arg = nil
|
240
240
|
object.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
|
@@ -242,41 +242,41 @@ module RR
|
|
242
242
|
end
|
243
243
|
|
244
244
|
it "sets return value when block passed in" do
|
245
|
-
|
245
|
+
double.with_any_args.yields {:return_value}
|
246
246
|
object.foobar {}.should == :return_value
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
250
|
describe "#after_call" do
|
251
251
|
it "returns DoubleDefinition" do
|
252
|
-
|
252
|
+
double.after_call {}.should === double.definition
|
253
253
|
end
|
254
254
|
|
255
255
|
it "sends return value of Double implementation to after_call" do
|
256
256
|
return_value = {}
|
257
|
-
|
257
|
+
double.returns(return_value).after_call do |value|
|
258
258
|
value[:foo] = :bar
|
259
259
|
value
|
260
260
|
end
|
261
261
|
|
262
|
-
actual_value =
|
262
|
+
actual_value = double.call(double_insertion)
|
263
263
|
actual_value.should === return_value
|
264
264
|
actual_value.should == {:foo => :bar}
|
265
265
|
end
|
266
266
|
|
267
267
|
it "receives the return value in the after_call callback" do
|
268
268
|
return_value = :returns_value
|
269
|
-
|
269
|
+
double.returns(return_value).after_call do |value|
|
270
270
|
:after_call_value
|
271
271
|
end
|
272
272
|
|
273
|
-
actual_value =
|
273
|
+
actual_value = double.call(double_insertion)
|
274
274
|
actual_value.should == :after_call_value
|
275
275
|
end
|
276
276
|
|
277
277
|
it "allows after_call to mock the return value" do
|
278
278
|
return_value = Object.new
|
279
|
-
|
279
|
+
double.with_any_args.returns(return_value).after_call do |value|
|
280
280
|
mock(value).inner_method(1) {:baz}
|
281
281
|
value
|
282
282
|
end
|
@@ -286,66 +286,66 @@ module RR
|
|
286
286
|
|
287
287
|
it "raises an error when not passed a block" do
|
288
288
|
proc do
|
289
|
-
|
289
|
+
double.after_call
|
290
290
|
end.should raise_error(ArgumentError, "after_call expects a block")
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
294
|
describe "#returns" do
|
295
295
|
it "returns DoubleDefinition" do
|
296
|
-
|
297
|
-
|
296
|
+
double.returns {:baz}.should === double.definition
|
297
|
+
double.returns(:baz).should === double.definition
|
298
298
|
end
|
299
299
|
|
300
300
|
it "sets the value of the method when passed a block" do
|
301
|
-
|
302
|
-
|
301
|
+
double.returns {:baz}
|
302
|
+
double.call(double_insertion).should == :baz
|
303
303
|
end
|
304
304
|
|
305
305
|
it "sets the value of the method when passed an argument" do
|
306
|
-
|
307
|
-
|
306
|
+
double.returns(:baz)
|
307
|
+
double.call(double_insertion).should == :baz
|
308
308
|
end
|
309
309
|
|
310
310
|
it "returns false when passed false" do
|
311
|
-
|
312
|
-
|
311
|
+
double.returns(false)
|
312
|
+
double.call(double_insertion).should == false
|
313
313
|
end
|
314
314
|
|
315
315
|
it "raises an error when both argument and block is passed in" do
|
316
316
|
proc do
|
317
|
-
|
317
|
+
double.returns(:baz) {:another}
|
318
318
|
end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
|
319
319
|
end
|
320
320
|
end
|
321
321
|
|
322
322
|
describe "#implemented_by" do
|
323
323
|
it "returns the DoubleDefinition" do
|
324
|
-
|
324
|
+
double.implemented_by(proc{:baz}).should === double.definition
|
325
325
|
end
|
326
326
|
|
327
327
|
it "sets the implementation to the passed in proc" do
|
328
|
-
|
329
|
-
|
328
|
+
double.implemented_by(proc{:baz})
|
329
|
+
double.call(double_insertion).should == :baz
|
330
330
|
end
|
331
331
|
|
332
332
|
it "sets the implementation to the passed in method" do
|
333
333
|
def object.foobar(a, b)
|
334
334
|
[b, a]
|
335
335
|
end
|
336
|
-
|
337
|
-
|
336
|
+
double.implemented_by(object.method(:foobar))
|
337
|
+
double.call(double_insertion, 1, 2).should == [2, 1]
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
341
341
|
describe "#implemented_by_original_method" do
|
342
342
|
it "returns the DoubleDefinition object" do
|
343
|
-
|
343
|
+
double.implemented_by_original_method.should === double.definition
|
344
344
|
end
|
345
345
|
|
346
346
|
it "sets the implementation to the original method" do
|
347
|
-
|
348
|
-
|
347
|
+
double.implemented_by_original_method
|
348
|
+
double.call(double_insertion, 1, 2).should == [2, 1]
|
349
349
|
end
|
350
350
|
|
351
351
|
it "calls methods when respond_to? is true and methods does not contain original method" do
|
@@ -366,9 +366,9 @@ module RR
|
|
366
366
|
end
|
367
367
|
|
368
368
|
double_insertion = space.double_insertion(object, :foobar)
|
369
|
-
|
370
|
-
|
371
|
-
|
369
|
+
double = space.double(double_insertion)
|
370
|
+
double.with_any_args
|
371
|
+
double.implemented_by_original_method
|
372
372
|
|
373
373
|
object.foobar(1, 2).should == [2, 1]
|
374
374
|
end
|
@@ -380,9 +380,9 @@ module RR
|
|
380
380
|
end
|
381
381
|
end
|
382
382
|
double_insertion = space.double_insertion(object, :does_not_exist)
|
383
|
-
|
384
|
-
|
385
|
-
|
383
|
+
double = space.double(double_insertion)
|
384
|
+
double.with_any_args
|
385
|
+
double.implemented_by_original_method
|
386
386
|
|
387
387
|
return_value = object.does_not_exist(1, 2)
|
388
388
|
return_value.should == "method_missing for does_not_exist([1, 2])"
|
@@ -391,40 +391,40 @@ module RR
|
|
391
391
|
|
392
392
|
describe "#call implemented by a proc" do
|
393
393
|
it "calls the return proc when implemented by a proc" do
|
394
|
-
|
395
|
-
|
394
|
+
double.returns {|arg| "returning #{arg}"}
|
395
|
+
double.call(double_insertion, :foobar).should == "returning foobar"
|
396
396
|
end
|
397
397
|
|
398
398
|
it "calls and returns the after_call when after_call is set" do
|
399
|
-
|
399
|
+
double.returns {|arg| "returning #{arg}"}.after_call do |value|
|
400
400
|
"#{value} after call"
|
401
401
|
end
|
402
|
-
|
402
|
+
double.call(double_insertion, :foobar).should == "returning foobar after call"
|
403
403
|
end
|
404
404
|
|
405
405
|
it "returns nil when to returns is not set" do
|
406
|
-
|
406
|
+
double.call(double_insertion).should be_nil
|
407
407
|
end
|
408
408
|
|
409
409
|
it "works when times_called is not set" do
|
410
|
-
|
411
|
-
|
410
|
+
double.returns {:value}
|
411
|
+
double.call(double_insertion)
|
412
412
|
end
|
413
413
|
|
414
414
|
it "verifes the times_called does not exceed the TimesCalledExpectation" do
|
415
|
-
|
415
|
+
double.times(2).returns {:value}
|
416
416
|
|
417
|
-
|
418
|
-
|
419
|
-
proc {
|
417
|
+
double.call(double_insertion, :foobar)
|
418
|
+
double.call(double_insertion, :foobar)
|
419
|
+
proc {double.call(double_insertion, :foobar)}.should raise_error(Errors::TimesCalledError)
|
420
420
|
end
|
421
421
|
|
422
422
|
it "raises DoubleOrderError when ordered and called out of order" do
|
423
|
-
|
424
|
-
|
423
|
+
double1 = double
|
424
|
+
double2 = space.double(double_insertion)
|
425
425
|
|
426
|
-
|
427
|
-
|
426
|
+
double1.with(1).returns {:return_1}.ordered.once
|
427
|
+
double2.with(2).returns {:return_2}.ordered.once
|
428
428
|
|
429
429
|
proc do
|
430
430
|
object.foobar(2)
|
@@ -436,59 +436,59 @@ module RR
|
|
436
436
|
)
|
437
437
|
end
|
438
438
|
|
439
|
-
it "dispatches to Space#
|
440
|
-
|
441
|
-
|
442
|
-
space.method(:
|
439
|
+
it "dispatches to Space#verify_ordered_double when ordered" do
|
440
|
+
verify_ordered_double_called = false
|
441
|
+
passed_in_double = nil
|
442
|
+
space.method(:verify_ordered_double).arity.should == 1
|
443
443
|
(
|
444
444
|
class << space;
|
445
445
|
self;
|
446
446
|
end).class_eval do
|
447
|
-
define_method :
|
448
|
-
|
449
|
-
|
447
|
+
define_method :verify_ordered_double do |double|
|
448
|
+
passed_in_double = double
|
449
|
+
verify_ordered_double_called = true
|
450
450
|
end
|
451
451
|
end
|
452
452
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
453
|
+
double.returns {:value}.ordered
|
454
|
+
double.call(double_insertion, :foobar)
|
455
|
+
verify_ordered_double_called.should be_true
|
456
|
+
passed_in_double.should === double
|
457
457
|
end
|
458
458
|
|
459
|
-
it "does not dispatche to Space#
|
460
|
-
|
461
|
-
space.method(:
|
459
|
+
it "does not dispatche to Space#verify_ordered_double when not ordered" do
|
460
|
+
verify_ordered_double_called = false
|
461
|
+
space.method(:verify_ordered_double).arity.should == 1
|
462
462
|
(
|
463
463
|
class << space;
|
464
464
|
self;
|
465
465
|
end).class_eval do
|
466
|
-
define_method :
|
467
|
-
|
466
|
+
define_method :verify_ordered_double do |double|
|
467
|
+
verify_ordered_double_called = true
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
471
|
-
|
472
|
-
|
473
|
-
|
471
|
+
double.returns {:value}
|
472
|
+
double.call(double_insertion, :foobar)
|
473
|
+
verify_ordered_double_called.should be_false
|
474
474
|
end
|
475
475
|
|
476
476
|
it "does not add block argument if no block passed in" do
|
477
|
-
|
477
|
+
double.with(1, 2).returns {|*args| args}
|
478
478
|
|
479
479
|
args = object.foobar(1, 2)
|
480
480
|
args.should == [1, 2]
|
481
481
|
end
|
482
482
|
|
483
483
|
it "makes the block the last argument" do
|
484
|
-
|
484
|
+
double.with(1, 2).returns {|a, b, blk| blk}
|
485
485
|
|
486
486
|
block = object.foobar(1, 2) {|a, b| [b, a]}
|
487
487
|
block.call(3, 4).should == [4, 3]
|
488
488
|
end
|
489
489
|
|
490
490
|
it "raises ArgumentError when yields was called and no block passed in" do
|
491
|
-
|
491
|
+
double.with(1, 2).yields(55)
|
492
492
|
|
493
493
|
proc do
|
494
494
|
object.foobar(1, 2)
|
@@ -502,7 +502,7 @@ module RR
|
|
502
502
|
yield(a, b)
|
503
503
|
end
|
504
504
|
|
505
|
-
|
505
|
+
double.with(1, 2).implemented_by(object.method(:foobar))
|
506
506
|
|
507
507
|
object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
|
508
508
|
end
|
@@ -510,144 +510,144 @@ module RR
|
|
510
510
|
|
511
511
|
describe "#exact_match?" do
|
512
512
|
it "returns false when no expectation set" do
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
513
|
+
double.should_not be_exact_match()
|
514
|
+
double.should_not be_exact_match(nil)
|
515
|
+
double.should_not be_exact_match(Object.new)
|
516
|
+
double.should_not be_exact_match(1, 2, 3)
|
517
517
|
end
|
518
518
|
|
519
519
|
it "returns false when arguments are not an exact match" do
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
520
|
+
double.with(1, 2, 3)
|
521
|
+
double.should_not be_exact_match(1, 2)
|
522
|
+
double.should_not be_exact_match(1)
|
523
|
+
double.should_not be_exact_match()
|
524
|
+
double.should_not be_exact_match("does not match")
|
525
525
|
end
|
526
526
|
|
527
527
|
it "returns true when arguments are an exact match" do
|
528
|
-
|
529
|
-
|
528
|
+
double.with(1, 2, 3)
|
529
|
+
double.should be_exact_match(1, 2, 3)
|
530
530
|
end
|
531
531
|
end
|
532
532
|
|
533
533
|
describe "#wildcard_match?" do
|
534
534
|
it "returns false when no expectation set" do
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
535
|
+
double.should_not be_wildcard_match()
|
536
|
+
double.should_not be_wildcard_match(nil)
|
537
|
+
double.should_not be_wildcard_match(Object.new)
|
538
|
+
double.should_not be_wildcard_match(1, 2, 3)
|
539
539
|
end
|
540
540
|
|
541
541
|
it "returns true when arguments are an exact match" do
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
542
|
+
double.with(1, 2, 3)
|
543
|
+
double.should be_wildcard_match(1, 2, 3)
|
544
|
+
double.should_not be_wildcard_match(1, 2)
|
545
|
+
double.should_not be_wildcard_match(1)
|
546
|
+
double.should_not be_wildcard_match()
|
547
|
+
double.should_not be_wildcard_match("does not match")
|
548
548
|
end
|
549
549
|
|
550
550
|
it "returns true when with_any_args" do
|
551
|
-
|
551
|
+
double.with_any_args
|
552
552
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
553
|
+
double.should be_wildcard_match(1, 2, 3)
|
554
|
+
double.should be_wildcard_match(1, 2)
|
555
|
+
double.should be_wildcard_match(1)
|
556
|
+
double.should be_wildcard_match()
|
557
|
+
double.should be_wildcard_match("does not match")
|
558
558
|
end
|
559
559
|
end
|
560
560
|
|
561
561
|
describe "#attempt?" do
|
562
562
|
it "returns true when TimesCalledExpectation#attempt? is true" do
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
563
|
+
double.with(1, 2, 3).twice
|
564
|
+
double.call(double_insertion, 1, 2, 3)
|
565
|
+
double.times_called_expectation.should be_attempt
|
566
|
+
double.should be_attempt
|
567
567
|
end
|
568
568
|
|
569
569
|
it "returns false when TimesCalledExpectation#attempt? is true" do
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
570
|
+
double.with(1, 2, 3).twice
|
571
|
+
double.call(double_insertion, 1, 2, 3)
|
572
|
+
double.call(double_insertion, 1, 2, 3)
|
573
|
+
double.times_called_expectation.should_not be_attempt
|
574
|
+
double.should_not be_attempt
|
575
575
|
end
|
576
576
|
|
577
577
|
it "returns true when there is no Times Called expectation" do
|
578
|
-
|
579
|
-
|
580
|
-
|
578
|
+
double.with(1, 2, 3)
|
579
|
+
double.definition.times_matcher.should be_nil
|
580
|
+
double.should be_attempt
|
581
581
|
end
|
582
582
|
end
|
583
583
|
|
584
584
|
describe "#verify" do
|
585
585
|
it "verifies that times called expectation was met" do
|
586
|
-
|
586
|
+
double.twice.returns {:return_value}
|
587
587
|
|
588
|
-
proc {
|
589
|
-
|
590
|
-
proc {
|
591
|
-
|
588
|
+
proc {double.verify}.should raise_error(Errors::TimesCalledError)
|
589
|
+
double.call(double_insertion)
|
590
|
+
proc {double.verify}.should raise_error(Errors::TimesCalledError)
|
591
|
+
double.call(double_insertion)
|
592
592
|
|
593
|
-
proc {
|
593
|
+
proc {double.verify}.should_not raise_error
|
594
594
|
end
|
595
595
|
|
596
596
|
it "does not raise an error when there is no times called expectation" do
|
597
|
-
proc {
|
598
|
-
|
599
|
-
proc {
|
600
|
-
|
601
|
-
proc {
|
597
|
+
proc {double.verify}.should_not raise_error
|
598
|
+
double.call(double_insertion)
|
599
|
+
proc {double.verify}.should_not raise_error
|
600
|
+
double.call(double_insertion)
|
601
|
+
proc {double.verify}.should_not raise_error
|
602
602
|
end
|
603
603
|
end
|
604
604
|
|
605
605
|
describe "#terminal?" do
|
606
606
|
it "returns true when times_called_expectation's terminal? is true" do
|
607
|
-
|
608
|
-
|
609
|
-
|
607
|
+
double.once
|
608
|
+
double.times_called_expectation.should be_terminal
|
609
|
+
double.should be_terminal
|
610
610
|
end
|
611
611
|
|
612
612
|
it "returns false when times_called_expectation's terminal? is false" do
|
613
|
-
|
614
|
-
|
615
|
-
|
613
|
+
double.any_number_of_times
|
614
|
+
double.times_called_expectation.should_not be_terminal
|
615
|
+
double.should_not be_terminal
|
616
616
|
end
|
617
617
|
|
618
618
|
it "returns false when there is no times_matcher" do
|
619
|
-
|
620
|
-
|
619
|
+
double.definition.times_matcher.should be_nil
|
620
|
+
double.should_not be_terminal
|
621
621
|
end
|
622
622
|
end
|
623
623
|
|
624
624
|
describe "#method_name" do
|
625
625
|
it "returns the DoubleInjection's method_name" do
|
626
626
|
double_insertion.method_name.should == :foobar
|
627
|
-
|
627
|
+
double.method_name.should == :foobar
|
628
628
|
end
|
629
629
|
end
|
630
630
|
|
631
631
|
describe "#expected_arguments" do
|
632
632
|
it "returns argument expectation's expected_arguments when there is a argument expectation" do
|
633
|
-
|
634
|
-
|
633
|
+
double.with(1, 2)
|
634
|
+
double.expected_arguments.should == [1, 2]
|
635
635
|
end
|
636
636
|
|
637
637
|
it "returns an empty array when there is no argument expectation" do
|
638
|
-
|
639
|
-
|
638
|
+
double.argument_expectation.should be_nil
|
639
|
+
double.expected_arguments.should == []
|
640
640
|
end
|
641
641
|
end
|
642
642
|
|
643
643
|
describe "#formatted_name" do
|
644
644
|
it "renders the formatted name of the Double with no arguments" do
|
645
|
-
|
645
|
+
double.formatted_name.should == "foobar()"
|
646
646
|
end
|
647
647
|
|
648
648
|
it "renders the formatted name of the Double with arguments" do
|
649
|
-
|
650
|
-
|
649
|
+
double.with(1, 2)
|
650
|
+
double.formatted_name.should == "foobar(1, 2)"
|
651
651
|
end
|
652
652
|
end
|
653
653
|
end
|