rr 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +10 -0
- data/README.rdoc +56 -18
- data/Rakefile +1 -2
- data/lib/rr.rb +14 -5
- data/lib/rr/adapters/rr_methods.rb +11 -0
- data/lib/rr/adapters/rspec.rb +30 -0
- data/lib/rr/adapters/test_unit.rb +4 -0
- data/lib/rr/double.rb +79 -227
- data/lib/rr/double_definitions/child_double_definition_creator.rb +4 -0
- data/lib/rr/double_definitions/double_definition.rb +138 -4
- data/lib/rr/double_definitions/double_definition_creator.rb +18 -4
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +35 -3
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +3 -0
- data/lib/rr/double_injection.rb +10 -6
- data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
- data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
- data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
- data/lib/rr/expectations/times_called_expectation.rb +11 -9
- data/lib/rr/recorded_calls.rb +103 -0
- data/lib/rr/space.rb +18 -8
- data/lib/rr/spy_verification.rb +48 -0
- data/lib/rr/spy_verification_proxy.rb +18 -0
- data/lib/rr/times_called_matchers/any_times_matcher.rb +2 -3
- data/lib/rr/times_called_matchers/at_least_matcher.rb +2 -3
- data/lib/rr/times_called_matchers/at_most_matcher.rb +2 -3
- data/lib/rr/times_called_matchers/times_called_matcher.rb +4 -4
- data/spec/core_spec_suite.rb +1 -0
- data/spec/high_level_spec.rb +151 -14
- data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +9 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +91 -19
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +7 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +53 -10
- data/spec/rr/double_injection/double_injection_dispatching_spec.rb +14 -15
- data/spec/rr/double_injection/double_injection_verify_spec.rb +1 -1
- data/spec/rr/double_spec.rb +79 -445
- data/spec/rr/errors/rr_error_spec.rb +49 -47
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +4 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +3 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +3 -2
- 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 +3 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +6 -5
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +3 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +3 -2
- data/spec/rr/rspec/invocation_matcher_spec.rb +259 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +1 -1
- data/spec/rr/rspec/rspec_usage_spec.rb +43 -24
- data/spec/rr/space/hash_with_object_id_key_spec.rb +2 -2
- data/spec/rr/space/space_spec.rb +27 -9
- data/spec/rr/test_unit/test_unit_integration_test.rb +10 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/spy_verification_spec.rb +129 -0
- metadata +100 -88
@@ -74,8 +74,8 @@ module RR
|
|
74
74
|
RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject_2)
|
75
75
|
)
|
76
76
|
|
77
|
-
double_1.ordered
|
78
|
-
double_2.ordered
|
77
|
+
double_1.definition.ordered
|
78
|
+
double_2.definition.ordered
|
79
79
|
|
80
80
|
space.ordered_doubles.should_not be_empty
|
81
81
|
|
@@ -11,6 +11,15 @@ module RR
|
|
11
11
|
@parent_double_definition = DoubleDefinition.new(parent_double_definition_creator, parent_subject)
|
12
12
|
@child_double_definition_creator = ChildDoubleDefinitionCreator.new(parent_double_definition)
|
13
13
|
end
|
14
|
+
|
15
|
+
describe "#root_subject" do
|
16
|
+
it "returns the #parent_double_definition.root_subject" do
|
17
|
+
child_subject = Object.new
|
18
|
+
parent_double_definition_creator.stub(parent_subject)
|
19
|
+
child_double_definition_creator.stub(child_subject)
|
20
|
+
child_double_definition_creator.root_subject.should == parent_subject
|
21
|
+
end
|
22
|
+
end
|
14
23
|
|
15
24
|
describe "Strategies::Verification definitions" do
|
16
25
|
describe "methods without !" do
|
@@ -46,34 +46,106 @@ module RR
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context "
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
context "when passed a block" do
|
50
|
+
macro("calls the block to define the Doubles") do
|
51
|
+
send "initializes proxy with passed in creator"
|
52
|
+
|
53
|
+
it "creates double_injections" do
|
54
|
+
subject.foobar(1, 2).should == :one_two
|
55
|
+
subject.foobar(1).should == :one
|
56
|
+
subject.foobar(:something).should == :default
|
57
|
+
subject.baz.should == :baz_result
|
58
|
+
end
|
59
|
+
|
60
|
+
it "clears out all methods from proxy" do
|
61
|
+
proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
|
62
|
+
def i_should_be_a_double
|
63
|
+
end
|
64
|
+
end
|
65
|
+
proxy_subclass.instance_methods.map {|m| m.to_s}.should include('i_should_be_a_double')
|
66
|
+
|
67
|
+
proxy_subclass.new(creator) do |m|
|
68
|
+
m.i_should_be_a_double.should be_instance_of(DoubleDefinition)
|
69
|
+
end
|
56
70
|
end
|
57
71
|
end
|
58
72
|
|
59
|
-
|
73
|
+
context "when the block has an arity of 1" do
|
74
|
+
attr_reader :passed_in_argument
|
75
|
+
before do
|
76
|
+
passed_in_argument = nil
|
77
|
+
block = lambda do |b|
|
78
|
+
passed_in_argument = b
|
79
|
+
b.foobar(1, 2) {:one_two}
|
80
|
+
b.foobar(1) {:one}
|
81
|
+
b.foobar.with_any_args {:default}
|
82
|
+
b.baz() {:baz_result}
|
83
|
+
end
|
84
|
+
block.arity.should == 1
|
85
|
+
|
86
|
+
@the_proxy = DoubleDefinitionCreatorProxy.new(creator, &block)
|
87
|
+
@passed_in_argument = passed_in_argument
|
88
|
+
end
|
89
|
+
|
90
|
+
send("calls the block to define the Doubles")
|
60
91
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
subject.foobar(:something).should == :default
|
65
|
-
subject.baz.should == :baz_result
|
92
|
+
it "passes the self into the block" do
|
93
|
+
passed_in_argument.__creator__.should == creator
|
94
|
+
end
|
66
95
|
end
|
67
96
|
|
68
|
-
|
69
|
-
|
70
|
-
|
97
|
+
context "when the block has an arity of -1" do
|
98
|
+
attr_reader :self_value, :passed_in_arguments
|
99
|
+
before do
|
100
|
+
self_value = nil
|
101
|
+
passed_in_arguments = nil
|
102
|
+
block = lambda do |*args|
|
103
|
+
self_value = self
|
104
|
+
passed_in_arguments = args
|
105
|
+
args[0].foobar(1, 2) {:one_two}
|
106
|
+
args[0].foobar(1) {:one}
|
107
|
+
args[0].foobar.with_any_args {:default}
|
108
|
+
args[0].baz() {:baz_result}
|
71
109
|
end
|
110
|
+
block.arity.should == -1
|
111
|
+
|
112
|
+
@the_proxy = DoubleDefinitionCreatorProxy.new(creator, &block)
|
113
|
+
@self_value = self_value
|
114
|
+
@passed_in_arguments = passed_in_arguments
|
72
115
|
end
|
73
|
-
proxy_subclass.instance_methods.map {|m| m.to_s}.should include('i_should_be_a_double')
|
74
116
|
|
75
|
-
|
76
|
-
|
117
|
+
send("calls the block to define the Doubles")
|
118
|
+
|
119
|
+
it "passes the self into the block" do
|
120
|
+
passed_in_arguments.map {|a| a.__creator__}.should == [creator]
|
121
|
+
end
|
122
|
+
|
123
|
+
it "evaluates the block with the context of self" do
|
124
|
+
self_value.__creator__.should == creator
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when the block has an arity of 0" do
|
129
|
+
attr_reader :self_value
|
130
|
+
before do
|
131
|
+
self_value = nil
|
132
|
+
block = lambda do ||
|
133
|
+
self_value = self
|
134
|
+
foobar(1, 2) {:one_two}
|
135
|
+
foobar(1) {:one}
|
136
|
+
foobar.with_any_args {:default}
|
137
|
+
baz() {:baz_result}
|
138
|
+
end
|
139
|
+
block.arity.should == 0
|
140
|
+
|
141
|
+
@the_proxy = DoubleDefinitionCreatorProxy.new(creator, &block)
|
142
|
+
@self_value = self_value
|
143
|
+
end
|
144
|
+
|
145
|
+
send("calls the block to define the Doubles")
|
146
|
+
|
147
|
+
it "evaluates the block with the context of self" do
|
148
|
+
self_value.__creator__.should == creator
|
77
149
|
end
|
78
150
|
end
|
79
151
|
end
|
@@ -9,6 +9,13 @@ module RR
|
|
9
9
|
@subject = Object.new
|
10
10
|
@creator = DoubleDefinitionCreator.new
|
11
11
|
end
|
12
|
+
|
13
|
+
describe "#root_subject" do
|
14
|
+
it "returns #subject" do
|
15
|
+
creator.stub(subject).foobar
|
16
|
+
creator.root_subject.should == subject
|
17
|
+
end
|
18
|
+
end
|
12
19
|
|
13
20
|
describe "StrategySetupMethods" do
|
14
21
|
describe "normal strategy definitions" do
|
@@ -3,16 +3,16 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
|
3
3
|
module RR
|
4
4
|
module DoubleDefinitions
|
5
5
|
describe DoubleDefinition do
|
6
|
-
attr_reader :subject, :
|
6
|
+
attr_reader :subject, :double_definition_creator, :double, :definition
|
7
7
|
|
8
8
|
it_should_behave_like "Swapped Space"
|
9
9
|
|
10
10
|
before do
|
11
11
|
@subject = Object.new
|
12
12
|
add_original_method
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
13
|
+
@double_definition_creator = DoubleDefinitionCreator.new
|
14
|
+
@definition = double_definition_creator.stub(subject).foobar
|
15
|
+
@double = definition.double
|
16
16
|
end
|
17
17
|
|
18
18
|
def add_original_method
|
@@ -20,6 +20,13 @@ module RR
|
|
20
20
|
:original_return_value
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
describe "#root_subject" do
|
25
|
+
it "returns #double_definition_creator.root_subject" do
|
26
|
+
definition.root_subject.should == definition.double_definition_creator.root_subject
|
27
|
+
definition.root_subject.should == subject
|
28
|
+
end
|
29
|
+
end
|
23
30
|
|
24
31
|
describe "DefinitionConstructionMethods" do
|
25
32
|
macro("DoubleDefinition where #double_definition_creator is a Reimplementation") do
|
@@ -888,6 +895,18 @@ module RR
|
|
888
895
|
definition.should be_verbose
|
889
896
|
end
|
890
897
|
end
|
898
|
+
|
899
|
+
describe "#verify_method_signature" do
|
900
|
+
it "sets #verify_method_signature? to true" do
|
901
|
+
definition.verify_method_signature?.should be_false
|
902
|
+
definition.verify_method_signature
|
903
|
+
definition.verify_method_signature?.should be_true
|
904
|
+
end
|
905
|
+
|
906
|
+
it "returns self" do
|
907
|
+
definition.verify_method_signature.should == definition
|
908
|
+
end
|
909
|
+
end
|
891
910
|
end
|
892
911
|
|
893
912
|
describe "NestedDoubleCreationMethods" do
|
@@ -896,7 +915,7 @@ module RR
|
|
896
915
|
RR.verify(ChildDoubleDefinitionCreator)
|
897
916
|
RR.verify(child_double_definition_creator)
|
898
917
|
end
|
899
|
-
|
918
|
+
|
900
919
|
describe "#mock" do
|
901
920
|
it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #mock method with the passed-in arguments and block" do
|
902
921
|
child_subject = Object.new
|
@@ -905,7 +924,7 @@ module RR
|
|
905
924
|
mock.proxy(child_double_definition_creator).mock(child_subject, :baz)
|
906
925
|
child_double_definition_creator = child_double_definition_creator
|
907
926
|
end
|
908
|
-
|
927
|
+
|
909
928
|
definition.mock(child_subject, :baz)
|
910
929
|
@child_double_definition_creator = child_double_definition_creator
|
911
930
|
end
|
@@ -999,6 +1018,28 @@ module RR
|
|
999
1018
|
end.should raise_error(Errors::DoubleDefinitionError)
|
1000
1019
|
end
|
1001
1020
|
end
|
1021
|
+
|
1022
|
+
describe "#strong" do
|
1023
|
+
it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #strong method with the passed-in arguments and block" do
|
1024
|
+
child_subject = Object.new
|
1025
|
+
child_double_definition_creator = nil
|
1026
|
+
mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
|
1027
|
+
mock.proxy(child_double_definition_creator).strong(DoubleDefinitionCreator::NO_SUBJECT, nil)
|
1028
|
+
child_double_definition_creator = child_double_definition_creator
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
definition.strong.mock(child_subject)
|
1032
|
+
@child_double_definition_creator = child_double_definition_creator
|
1033
|
+
end
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
describe "#strong!" do
|
1037
|
+
it "raises a DoubleDefinitionError" do
|
1038
|
+
lambda do
|
1039
|
+
definition.strong!(:baz)
|
1040
|
+
end.should raise_error(Errors::DoubleDefinitionError)
|
1041
|
+
end
|
1042
|
+
end
|
1002
1043
|
end
|
1003
1044
|
|
1004
1045
|
describe "StateQueryMethods" do
|
@@ -1009,8 +1050,9 @@ module RR
|
|
1009
1050
|
end
|
1010
1051
|
|
1011
1052
|
describe "#exact_match?" do
|
1012
|
-
context "when no
|
1053
|
+
context "when no argument_expectation set" do
|
1013
1054
|
it "raises a DoubleDefinitionError" do
|
1055
|
+
definition.argument_expectation = nil
|
1014
1056
|
lambda do
|
1015
1057
|
definition.exact_match?
|
1016
1058
|
end.should raise_error(Errors::DoubleDefinitionError)
|
@@ -1036,8 +1078,9 @@ module RR
|
|
1036
1078
|
end
|
1037
1079
|
|
1038
1080
|
describe "#wildcard_match?" do
|
1039
|
-
context "when no
|
1081
|
+
context "when no #argument_expectation is set" do
|
1040
1082
|
it "raises a DoubleDefinitionError" do
|
1083
|
+
definition.argument_expectation = nil
|
1041
1084
|
lambda do
|
1042
1085
|
definition.wildcard_match?
|
1043
1086
|
end.should raise_error(Errors::DoubleDefinitionError)
|
@@ -1087,7 +1130,7 @@ module RR
|
|
1087
1130
|
|
1088
1131
|
context "when there is not times_matcher" do
|
1089
1132
|
it "raises a DoubleDefinitionError" do
|
1090
|
-
definition.times_matcher
|
1133
|
+
definition.times_matcher = nil
|
1091
1134
|
lambda do
|
1092
1135
|
definition.terminal?
|
1093
1136
|
end.should raise_error(Errors::DoubleDefinitionError)
|
@@ -1105,7 +1148,7 @@ module RR
|
|
1105
1148
|
|
1106
1149
|
context "when there is no argument expectation" do
|
1107
1150
|
it "returns an empty array" do
|
1108
|
-
definition.argument_expectation
|
1151
|
+
definition.argument_expectation = nil
|
1109
1152
|
definition.expected_arguments.should == []
|
1110
1153
|
end
|
1111
1154
|
end
|
@@ -16,7 +16,7 @@ module RR
|
|
16
16
|
DoubleDefinitions::DoubleDefinition.new(
|
17
17
|
DoubleDefinitions::DoubleDefinitionCreator.new,
|
18
18
|
subject
|
19
|
-
)
|
19
|
+
).any_number_of_times
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
@@ -34,7 +34,7 @@ module RR
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
double = new_double
|
37
|
-
double.with(1, 2).implemented_by(method_fixture.method(:method_with_block))
|
37
|
+
double.definition.with(1, 2).implemented_by(method_fixture.method(:method_with_block))
|
38
38
|
subject.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
|
39
39
|
end
|
40
40
|
end
|
@@ -42,11 +42,11 @@ module RR
|
|
42
42
|
context "when no other Double with duplicate ArgumentExpectations exists" do
|
43
43
|
it "dispatches to Double that have an exact match" do
|
44
44
|
double1_with_exact_match = new_double
|
45
|
-
double1_with_exact_match.with(:exact_match_1).returns {:return_1}
|
45
|
+
double1_with_exact_match.definition.with(:exact_match_1).returns {:return_1}
|
46
46
|
double_with_no_match = new_double
|
47
|
-
double_with_no_match.with("nothing that matches").returns {:no_match}
|
47
|
+
double_with_no_match.definition.with("nothing that matches").returns {:no_match}
|
48
48
|
double2_with_exact_match = new_double
|
49
|
-
double2_with_exact_match.with(:exact_match_2).returns {:return_2}
|
49
|
+
double2_with_exact_match.definition.with(:exact_match_2).returns {:return_2}
|
50
50
|
|
51
51
|
subject.foobar(:exact_match_1).should == :return_1
|
52
52
|
subject.foobar(:exact_match_2).should == :return_2
|
@@ -54,9 +54,9 @@ module RR
|
|
54
54
|
|
55
55
|
it "dispatches to Double that have a wildcard match" do
|
56
56
|
double_with_wildcard_match = new_double
|
57
|
-
double_with_wildcard_match.with_any_args.returns {:wild_card_value}
|
57
|
+
double_with_wildcard_match.definition.with_any_args.returns {:wild_card_value}
|
58
58
|
double_with_no_match = new_double
|
59
|
-
double_with_no_match.with("nothing that matches").returns {:no_match}
|
59
|
+
double_with_no_match.definition.with("nothing that matches").returns {:no_match}
|
60
60
|
|
61
61
|
subject.foobar(:wildcard_match_1).should == :wild_card_value
|
62
62
|
subject.foobar(:wildcard_match_2, 3).should == :wild_card_value
|
@@ -66,10 +66,10 @@ module RR
|
|
66
66
|
context "when other Doubles exists but none of them match the passed-in arguments" do
|
67
67
|
it "raises DoubleNotFoundError error when arguments do not match a double" do
|
68
68
|
double_1 = new_double
|
69
|
-
double_1.with(1, 2)
|
69
|
+
double_1.definition.with(1, 2)
|
70
70
|
|
71
71
|
double_2 = new_double
|
72
|
-
double_2.with(3)
|
72
|
+
double_2.definition.with(3)
|
73
73
|
|
74
74
|
error = nil
|
75
75
|
begin
|
@@ -122,7 +122,7 @@ module RR
|
|
122
122
|
|
123
123
|
def new_double(*arguments, &return_value)
|
124
124
|
double = super()
|
125
|
-
double.with(*arguments).any_number_of_times.returns(&return_value)
|
125
|
+
double.definition.with(*arguments).any_number_of_times.returns(&return_value)
|
126
126
|
double.should_not be_terminal
|
127
127
|
double
|
128
128
|
end
|
@@ -164,7 +164,7 @@ module RR
|
|
164
164
|
|
165
165
|
def new_double(*arguments, &return_value)
|
166
166
|
double = super()
|
167
|
-
double.with(*arguments).once.returns(&return_value)
|
167
|
+
double.definition.with(*arguments).once.returns(&return_value)
|
168
168
|
double.should be_terminal
|
169
169
|
double
|
170
170
|
end
|
@@ -206,7 +206,7 @@ module RR
|
|
206
206
|
|
207
207
|
def new_double(&return_value)
|
208
208
|
double = super
|
209
|
-
double.with_any_args.once.returns(&return_value)
|
209
|
+
double.definition.with_any_args.once.returns(&return_value)
|
210
210
|
double.should be_terminal
|
211
211
|
double
|
212
212
|
end
|
@@ -221,11 +221,10 @@ module RR
|
|
221
221
|
context "when the original method uses the passed-in block" do
|
222
222
|
it "executes the block" do
|
223
223
|
double = new_double
|
224
|
-
double.with(1, 2) {:return_value}
|
224
|
+
double.definition.with(1, 2) {:return_value}
|
225
225
|
subject.foobar!(1, 2).should == :return_value
|
226
226
|
end
|
227
227
|
end
|
228
|
-
|
229
228
|
end
|
230
229
|
|
231
230
|
describe "method names with ?" do
|
@@ -236,7 +235,7 @@ module RR
|
|
236
235
|
context "when the original method uses the passed-in block" do
|
237
236
|
it "executes the block" do
|
238
237
|
double = new_double
|
239
|
-
double.with(1, 2) {:return_value}
|
238
|
+
double.definition.with(1, 2) {:return_value}
|
240
239
|
subject.foobar?(1, 2).should == :return_value
|
241
240
|
end
|
242
241
|
end
|
@@ -19,7 +19,7 @@ module RR
|
|
19
19
|
)
|
20
20
|
double_injection.register_double double
|
21
21
|
|
22
|
-
double.with(1).once.returns {nil}
|
22
|
+
double.definition.with(1).once.returns {nil}
|
23
23
|
lambda {double_injection.verify}.should raise_error(Errors::TimesCalledError)
|
24
24
|
subject.foobar(1)
|
25
25
|
lambda {double_injection.verify}.should_not raise_error
|
data/spec/rr/double_spec.rb
CHANGED
@@ -11,7 +11,9 @@ module RR
|
|
11
11
|
end
|
12
12
|
@double_injection = create_double_injection
|
13
13
|
@definition_creator = DoubleDefinitions::DoubleDefinitionCreator.new
|
14
|
-
@definition = DoubleDefinitions::DoubleDefinition.new(definition_creator, subject)
|
14
|
+
@definition = DoubleDefinitions::DoubleDefinition.new(definition_creator, subject).
|
15
|
+
any_number_of_times.
|
16
|
+
with_any_args
|
15
17
|
@double = Double.new(double_injection, definition)
|
16
18
|
end
|
17
19
|
|
@@ -25,409 +27,16 @@ module RR
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
describe "#with" do
|
29
|
-
it "returns DoubleDefinition" do
|
30
|
-
double.with(1).should === double.definition
|
31
|
-
end
|
32
|
-
|
33
|
-
it "sets an ArgumentEqualityExpectation" do
|
34
|
-
double.with(1)
|
35
|
-
double.should be_exact_match(1)
|
36
|
-
double.should_not be_exact_match(2)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets return value when block passed in" do
|
40
|
-
double.with(1) {:return_value}
|
41
|
-
subject.foobar(1).should == :return_value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#with_any_args" do
|
46
|
-
before do
|
47
|
-
double.with_any_args {:return_value}
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns DoubleDefinition" do
|
51
|
-
double.with_no_args.should === double.definition
|
52
|
-
end
|
53
|
-
|
54
|
-
it "sets an AnyArgumentExpectation" do
|
55
|
-
double.should_not be_exact_match(1)
|
56
|
-
double.should be_wildcard_match(1)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "sets return value when block passed in" do
|
60
|
-
subject.foobar(:anything).should == :return_value
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#with_no_args" do
|
65
|
-
before do
|
66
|
-
double.with_no_args {:return_value}
|
67
|
-
end
|
68
|
-
|
69
|
-
it "returns DoubleDefinition" do
|
70
|
-
double.with_no_args.should === double.definition
|
71
|
-
end
|
72
|
-
|
73
|
-
it "sets an ArgumentEqualityExpectation with no arguments" do
|
74
|
-
double.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
|
75
|
-
end
|
76
|
-
|
77
|
-
it "sets return value when block passed in" do
|
78
|
-
subject.foobar().should == :return_value
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#never" do
|
83
|
-
it "returns DoubleDefinition" do
|
84
|
-
double.never.should === double.definition
|
85
|
-
end
|
86
|
-
|
87
|
-
it "sets up a Times Called Expectation with 0" do
|
88
|
-
double.never
|
89
|
-
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "sets return value when block passed in" do
|
93
|
-
double.with_any_args.never
|
94
|
-
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#once" do
|
99
|
-
it "returns DoubleDefinition" do
|
100
|
-
double.once.should === double.definition
|
101
|
-
end
|
102
|
-
|
103
|
-
it "sets up a Times Called Expectation with 1" do
|
104
|
-
double.once
|
105
|
-
double.call(double_injection)
|
106
|
-
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "sets return value when block passed in" do
|
110
|
-
double.with_any_args.once {:return_value}
|
111
|
-
subject.foobar.should == :return_value
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#twice" do
|
116
|
-
it "returns DoubleDefinition" do
|
117
|
-
double.twice.should === double.definition
|
118
|
-
end
|
119
|
-
|
120
|
-
it "sets up a Times Called Expectation with 2" do
|
121
|
-
double.twice
|
122
|
-
double.call(double_injection)
|
123
|
-
double.call(double_injection)
|
124
|
-
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "sets return value when block passed in" do
|
128
|
-
double.with_any_args.twice {:return_value}
|
129
|
-
subject.foobar.should == :return_value
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#at_least" do
|
134
|
-
it "returns DoubleDefinition" do
|
135
|
-
double.with_any_args.at_least(2).should === double.definition
|
136
|
-
end
|
137
|
-
|
138
|
-
it "sets up a AtLeastMatcher with 2" do
|
139
|
-
double.at_least(2)
|
140
|
-
double.definition.times_matcher.should == TimesCalledMatchers::AtLeastMatcher.new(2)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "sets return value when block passed in" do
|
144
|
-
double.with_any_args.at_least(2) {:return_value}
|
145
|
-
subject.foobar.should == :return_value
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "#at_most" do
|
150
|
-
it "returns DoubleDefinition" do
|
151
|
-
double.with_any_args.at_most(2).should === double.definition
|
152
|
-
end
|
153
|
-
|
154
|
-
it "sets up a Times Called Expectation with 1" do
|
155
|
-
double.at_most(2)
|
156
|
-
double.call(double_injection)
|
157
|
-
double.call(double_injection)
|
158
|
-
lambda do
|
159
|
-
double.call(double_injection)
|
160
|
-
end.should raise_error(
|
161
|
-
Errors::TimesCalledError,
|
162
|
-
"foobar()\nCalled 3 times.\nExpected at most 2 times."
|
163
|
-
)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "sets return value when block passed in" do
|
167
|
-
double.with_any_args.at_most(2) {:return_value}
|
168
|
-
subject.foobar.should == :return_value
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "#times" do
|
173
|
-
it "returns DoubleDefinition" do
|
174
|
-
double.times(3).should === double.definition
|
175
|
-
end
|
176
|
-
|
177
|
-
it "sets up a Times Called Expectation with passed in times" do
|
178
|
-
double.times(3)
|
179
|
-
double.call(double_injection)
|
180
|
-
double.call(double_injection)
|
181
|
-
double.call(double_injection)
|
182
|
-
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "sets return value when block passed in" do
|
186
|
-
double.with_any_args.times(3) {:return_value}
|
187
|
-
subject.foobar.should == :return_value
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "#any_number_of_times" do
|
192
|
-
it "returns DoubleDefinition" do
|
193
|
-
double.any_number_of_times.should === double.definition
|
194
|
-
end
|
195
|
-
|
196
|
-
it "sets up a Times Called Expectation with AnyTimes matcher" do
|
197
|
-
double.any_number_of_times
|
198
|
-
double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
199
|
-
end
|
200
|
-
|
201
|
-
it "sets return value when block passed in" do
|
202
|
-
double.with_any_args.any_number_of_times {:return_value}
|
203
|
-
subject.foobar.should == :return_value
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe "#ordered" do
|
208
|
-
it "adds itself to the ordered doubles list" do
|
209
|
-
double.ordered
|
210
|
-
space.ordered_doubles.should include(double)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "does not double_injection add itself" do
|
214
|
-
double.ordered
|
215
|
-
double.ordered
|
216
|
-
space.ordered_doubles.should == [double ]
|
217
|
-
end
|
218
|
-
|
219
|
-
it "sets ordered? to true" do
|
220
|
-
double.ordered
|
221
|
-
double.should be_ordered
|
222
|
-
end
|
223
|
-
|
224
|
-
it "sets return value when block passed in" do
|
225
|
-
double.with_any_args.once.ordered {:return_value}
|
226
|
-
subject.foobar.should == :return_value
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
30
|
describe "#ordered?" do
|
231
31
|
it "defaults to false" do
|
232
32
|
double.should_not be_ordered
|
233
33
|
end
|
234
34
|
end
|
235
35
|
|
236
|
-
describe "#yields" do
|
237
|
-
it "returns DoubleDefinition" do
|
238
|
-
double.yields(:baz).should === double.definition
|
239
|
-
end
|
240
|
-
|
241
|
-
it "yields the passed in argument to the call block when there is no returns value set" do
|
242
|
-
double.with_any_args.yields(:baz)
|
243
|
-
passed_in_block_arg = nil
|
244
|
-
subject.foobar {|arg| passed_in_block_arg = arg}.should == nil
|
245
|
-
passed_in_block_arg.should == :baz
|
246
|
-
end
|
247
|
-
|
248
|
-
it "yields the passed in argument to the call block when there is a no returns value set" do
|
249
|
-
double.with_any_args.yields(:baz).returns(:return_value)
|
250
|
-
|
251
|
-
passed_in_block_arg = nil
|
252
|
-
subject.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
|
253
|
-
passed_in_block_arg.should == :baz
|
254
|
-
end
|
255
|
-
|
256
|
-
it "sets return value when block passed in" do
|
257
|
-
double.with_any_args.yields {:return_value}
|
258
|
-
subject.foobar {}.should == :return_value
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
describe "#after_call" do
|
263
|
-
it "returns DoubleDefinition" do
|
264
|
-
double.after_call {}.should === double.definition
|
265
|
-
end
|
266
|
-
|
267
|
-
it "sends return value of Double implementation to after_call" do
|
268
|
-
return_value = {}
|
269
|
-
double.returns(return_value).after_call do |value|
|
270
|
-
value[:foo] = :bar
|
271
|
-
value
|
272
|
-
end
|
273
|
-
|
274
|
-
actual_value = double.call(double_injection)
|
275
|
-
actual_value.should === return_value
|
276
|
-
actual_value.should == {:foo => :bar}
|
277
|
-
end
|
278
|
-
|
279
|
-
it "receives the return value in the after_call callback" do
|
280
|
-
return_value = :returns_value
|
281
|
-
double.returns(return_value).after_call do |value|
|
282
|
-
:after_call_proc
|
283
|
-
end
|
284
|
-
|
285
|
-
actual_value = double.call(double_injection)
|
286
|
-
actual_value.should == :after_call_proc
|
287
|
-
end
|
288
|
-
|
289
|
-
it "allows after_call to mock the return value" do
|
290
|
-
return_value = Object.new
|
291
|
-
double.with_any_args.returns(return_value).after_call do |value|
|
292
|
-
mock(value).inner_method(1) {:baz}
|
293
|
-
value
|
294
|
-
end
|
295
|
-
|
296
|
-
subject.foobar.inner_method(1).should == :baz
|
297
|
-
end
|
298
|
-
|
299
|
-
it "raises an error when not passed a block" do
|
300
|
-
lambda do
|
301
|
-
double.after_call
|
302
|
-
end.should raise_error(ArgumentError, "after_call expects a block")
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
describe "#verbose" do
|
307
|
-
it "returns DoubleDefinition" do
|
308
|
-
double.verbose.should === double.definition
|
309
|
-
end
|
310
|
-
|
311
|
-
it "sets #verbose? to true" do
|
312
|
-
double.should_not be_verbose
|
313
|
-
double.verbose
|
314
|
-
double.should be_verbose
|
315
|
-
end
|
316
|
-
|
317
|
-
it "sets return value when block passed in" do
|
318
|
-
(class << double; self; end).__send__(:define_method, :puts) {|value|}
|
319
|
-
double.with().verbose {:return_value}
|
320
|
-
subject.foobar.should == :return_value
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "#returns" do
|
325
|
-
it "returns DoubleDefinition" do
|
326
|
-
double.returns {:baz}.should === double.definition
|
327
|
-
double.returns(:baz).should === double.definition
|
328
|
-
end
|
329
|
-
|
330
|
-
context "when passed a block" do
|
331
|
-
context "when the block returns a DoubleDefinition" do
|
332
|
-
it "causes #call to return the #subject of the DoubleDefinition" do
|
333
|
-
new_subject = Object.new
|
334
|
-
double.returns do
|
335
|
-
definition = stub(new_subject).foobar
|
336
|
-
definition.class.should == DoubleDefinitions::DoubleDefinition
|
337
|
-
definition
|
338
|
-
end
|
339
|
-
double.call(double_injection).should == new_subject
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
context "when the block returns a DoubleDefinitionCreatorProxy" do
|
344
|
-
it "causes #call to return the #subject of the DoubleDefinition" do
|
345
|
-
new_subject = Object.new
|
346
|
-
double.returns do
|
347
|
-
stub(new_subject)
|
348
|
-
end
|
349
|
-
double.call(double_injection).should == new_subject
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
context "when the block returns an Object" do
|
354
|
-
it "causes #call to return the value of the block" do
|
355
|
-
double.returns {:baz}
|
356
|
-
double.call(double_injection).should == :baz
|
357
|
-
end
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
context "when passed a return value argument" do
|
362
|
-
context "when passed a DoubleDefinition" do
|
363
|
-
it "causes #call to return the #subject of the DoubleDefinition" do
|
364
|
-
new_subject = Object.new
|
365
|
-
definition = stub(new_subject).foobar
|
366
|
-
definition.class.should == DoubleDefinitions::DoubleDefinition
|
367
|
-
|
368
|
-
double.returns(definition)
|
369
|
-
double.call(double_injection).should == new_subject
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
context "when passed a DoubleDefinitionCreatorProxy" do
|
374
|
-
it "causes #call to return the #subject of the DoubleDefinition" do
|
375
|
-
new_subject = Object.new
|
376
|
-
proxy = stub(new_subject)
|
377
|
-
proxy.__creator__.subject.should == new_subject
|
378
|
-
|
379
|
-
double.returns(proxy)
|
380
|
-
double.call(double_injection).should == new_subject
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
context "when passed an Object" do
|
385
|
-
it "causes #call to return the Object" do
|
386
|
-
double.returns(:baz)
|
387
|
-
double.call(double_injection).should == :baz
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
context "when passed false" do
|
392
|
-
it "causes #call to return false" do
|
393
|
-
double.returns(false)
|
394
|
-
double.call(double_injection).should == false
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
context "when passed both a return value argument and a block" do
|
400
|
-
it "raises an error" do
|
401
|
-
lambda do
|
402
|
-
double.returns(:baz) {:another}
|
403
|
-
end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
|
404
|
-
end
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
describe "#implemented_by" do
|
409
|
-
it "returns the DoubleDefinition" do
|
410
|
-
double.implemented_by(lambda{:baz}).should === double.definition
|
411
|
-
end
|
412
|
-
|
413
|
-
it "sets the implementation to the passed in Proc" do
|
414
|
-
double.implemented_by(lambda{:baz})
|
415
|
-
double.call(double_injection).should == :baz
|
416
|
-
end
|
417
|
-
|
418
|
-
it "sets the implementation to the passed in method" do
|
419
|
-
def subject.foobar(a, b)
|
420
|
-
[b, a]
|
421
|
-
end
|
422
|
-
double.implemented_by(subject.method(:foobar))
|
423
|
-
double.call(double_injection, 1, 2).should == [2, 1]
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
36
|
describe "#call" do
|
428
37
|
describe "when verbose" do
|
429
38
|
it "prints the message call" do
|
430
|
-
double.verbose
|
39
|
+
double.definition.verbose
|
431
40
|
output = nil
|
432
41
|
(class << double; self; end).__send__(:define_method, :puts) do |output|
|
433
42
|
output = output
|
@@ -450,12 +59,12 @@ module RR
|
|
450
59
|
|
451
60
|
describe "when implemented by a lambda" do
|
452
61
|
it "calls the return lambda when implemented by a lambda" do
|
453
|
-
double.returns {|arg| "returning #{arg}"}
|
62
|
+
double.definition.returns {|arg| "returning #{arg}"}
|
454
63
|
double.call(double_injection, :foobar).should == "returning foobar"
|
455
64
|
end
|
456
65
|
|
457
66
|
it "calls and returns the after_call when after_call is set" do
|
458
|
-
double.returns {|arg| "returning #{arg}"}.after_call do |value|
|
67
|
+
double.definition.returns {|arg| "returning #{arg}"}.after_call do |value|
|
459
68
|
"#{value} after call"
|
460
69
|
end
|
461
70
|
double.call(double_injection, :foobar).should == "returning foobar after call"
|
@@ -466,12 +75,12 @@ module RR
|
|
466
75
|
end
|
467
76
|
|
468
77
|
it "works when times_called is not set" do
|
469
|
-
double.returns {:value}
|
78
|
+
double.definition.returns {:value}
|
470
79
|
double.call(double_injection)
|
471
80
|
end
|
472
81
|
|
473
82
|
it "verifes the times_called does not exceed the TimesCalledExpectation" do
|
474
|
-
double.times(2).returns {:value}
|
83
|
+
double.definition.times(2).returns {:value}
|
475
84
|
|
476
85
|
double.call(double_injection, :foobar)
|
477
86
|
double.call(double_injection, :foobar)
|
@@ -482,8 +91,8 @@ module RR
|
|
482
91
|
double1 = double
|
483
92
|
double2 = Double.new(double_injection, DoubleDefinitions::DoubleDefinition.new(definition_creator, subject))
|
484
93
|
|
485
|
-
double1.with(1).returns {:return_1}.once.ordered
|
486
|
-
double2.with(2).returns {:return_2}.once.ordered
|
94
|
+
double1.definition.with(1).returns {:return_1}.once.ordered
|
95
|
+
double2.definition.with(2).returns {:return_2}.once.ordered
|
487
96
|
|
488
97
|
lambda do
|
489
98
|
subject.foobar(2)
|
@@ -506,7 +115,7 @@ module RR
|
|
506
115
|
end
|
507
116
|
end
|
508
117
|
|
509
|
-
double.returns {:value}.ordered
|
118
|
+
double.definition.returns {:value}.ordered
|
510
119
|
double.call(double_injection, :foobar)
|
511
120
|
verify_ordered_double_called.should be_true
|
512
121
|
passed_in_double.should === double
|
@@ -521,27 +130,27 @@ module RR
|
|
521
130
|
end
|
522
131
|
end
|
523
132
|
|
524
|
-
double.returns {:value}
|
133
|
+
double.definition.returns {:value}
|
525
134
|
double.call(double_injection, :foobar)
|
526
135
|
verify_ordered_double_called.should be_false
|
527
136
|
end
|
528
137
|
|
529
138
|
it "does not add block argument if no block passed in" do
|
530
|
-
double.with(1, 2).returns {|*args| args}
|
139
|
+
double.definition.with(1, 2).returns {|*args| args}
|
531
140
|
|
532
141
|
args = subject.foobar(1, 2)
|
533
142
|
args.should == [1, 2]
|
534
143
|
end
|
535
144
|
|
536
145
|
it "makes the block the last argument" do
|
537
|
-
double.with(1, 2).returns {|a, b, blk| blk}
|
146
|
+
double.definition.with(1, 2).returns {|a, b, blk| blk}
|
538
147
|
|
539
148
|
block = subject.foobar(1, 2) {|a, b| [b, a]}
|
540
149
|
block.call(3, 4).should == [4, 3]
|
541
150
|
end
|
542
151
|
|
543
152
|
it "raises ArgumentError when yields was called and no block passed in" do
|
544
|
-
double.with(1, 2).yields(55)
|
153
|
+
double.definition.with(1, 2).yields(55)
|
545
154
|
|
546
155
|
lambda do
|
547
156
|
subject.foobar(1, 2)
|
@@ -555,7 +164,7 @@ module RR
|
|
555
164
|
yield(a, b)
|
556
165
|
end
|
557
166
|
|
558
|
-
double.with(1, 2).implemented_by(subject.method(:foobar))
|
167
|
+
double.definition.with(1, 2).implemented_by(subject.method(:foobar))
|
559
168
|
|
560
169
|
subject.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
|
561
170
|
end
|
@@ -565,6 +174,7 @@ module RR
|
|
565
174
|
describe "#exact_match?" do
|
566
175
|
context "when no expectation is set" do
|
567
176
|
it "raises a DoubleDefinitionError" do
|
177
|
+
double.definition.argument_expectation = nil
|
568
178
|
lambda do
|
569
179
|
double.exact_match?
|
570
180
|
end.should raise_error(Errors::DoubleDefinitionError)
|
@@ -573,7 +183,7 @@ module RR
|
|
573
183
|
|
574
184
|
context "when arguments are not an exact match" do
|
575
185
|
it "returns false" do
|
576
|
-
double.with(1, 2, 3)
|
186
|
+
double.definition.with(1, 2, 3)
|
577
187
|
double.should_not be_exact_match(1, 2)
|
578
188
|
double.should_not be_exact_match(1)
|
579
189
|
double.should_not be_exact_match()
|
@@ -583,7 +193,7 @@ module RR
|
|
583
193
|
|
584
194
|
context "when arguments are an exact match" do
|
585
195
|
it "returns true" do
|
586
|
-
double.with(1, 2, 3)
|
196
|
+
double.definition.with(1, 2, 3)
|
587
197
|
double.should be_exact_match(1, 2, 3)
|
588
198
|
end
|
589
199
|
end
|
@@ -592,6 +202,7 @@ module RR
|
|
592
202
|
describe "#wildcard_match?" do
|
593
203
|
context "when no expectation set" do
|
594
204
|
it "raises a DoubleDefinitionError" do
|
205
|
+
double.definition.argument_expectation = nil
|
595
206
|
lambda do
|
596
207
|
double.wildcard_match?
|
597
208
|
end.should raise_error(Errors::DoubleDefinitionError)
|
@@ -600,7 +211,7 @@ module RR
|
|
600
211
|
|
601
212
|
context "when arguments are an exact match" do
|
602
213
|
it "returns true" do
|
603
|
-
double.with(1, 2, 3)
|
214
|
+
double.definition.with(1, 2, 3)
|
604
215
|
double.should be_wildcard_match(1, 2, 3)
|
605
216
|
double.should_not be_wildcard_match(1, 2)
|
606
217
|
double.should_not be_wildcard_match(1)
|
@@ -611,7 +222,7 @@ module RR
|
|
611
222
|
|
612
223
|
context "when with_any_args" do
|
613
224
|
it "returns true" do
|
614
|
-
double.with_any_args
|
225
|
+
double.definition.with_any_args
|
615
226
|
|
616
227
|
double.should be_wildcard_match(1, 2, 3)
|
617
228
|
double.should be_wildcard_match(1, 2)
|
@@ -623,31 +234,39 @@ module RR
|
|
623
234
|
end
|
624
235
|
|
625
236
|
describe "#attempt?" do
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
237
|
+
context "when TimesCalledExpectation#attempt? is true" do
|
238
|
+
it "returns true" do
|
239
|
+
double.definition.with(1, 2, 3).twice
|
240
|
+
double.call(double_injection, 1, 2, 3)
|
241
|
+
double.times_called_expectation.should be_attempt
|
242
|
+
double.should be_attempt
|
243
|
+
end
|
631
244
|
end
|
632
245
|
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
246
|
+
context "when TimesCalledExpectation#attempt? is true" do
|
247
|
+
it "returns false" do
|
248
|
+
double.definition.with(1, 2, 3).twice
|
249
|
+
double.call(double_injection, 1, 2, 3)
|
250
|
+
double.call(double_injection, 1, 2, 3)
|
251
|
+
double.times_called_expectation.should_not be_attempt
|
252
|
+
double.should_not be_attempt
|
253
|
+
end
|
639
254
|
end
|
640
255
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
256
|
+
context "when there is no Times Called expectation" do
|
257
|
+
it "raises a DoubleDefinitionError" do
|
258
|
+
double.definition.with(1, 2, 3)
|
259
|
+
double.definition.times_matcher = nil
|
260
|
+
lambda do
|
261
|
+
double.should be_attempt
|
262
|
+
end.should raise_error(RR::Errors::DoubleDefinitionError)
|
263
|
+
end
|
645
264
|
end
|
646
265
|
end
|
647
266
|
|
648
267
|
describe "#verify" do
|
649
268
|
it "verifies that times called expectation was met" do
|
650
|
-
double.twice.returns {:return_value}
|
269
|
+
double.definition.twice.returns {:return_value}
|
651
270
|
|
652
271
|
lambda {double.verify}.should raise_error(Errors::TimesCalledError)
|
653
272
|
double.call(double_injection)
|
@@ -667,21 +286,29 @@ module RR
|
|
667
286
|
end
|
668
287
|
|
669
288
|
describe "#terminal?" do
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
289
|
+
context "when times_called_expectation's terminal? is true" do
|
290
|
+
it "returns true" do
|
291
|
+
double.definition.once
|
292
|
+
double.times_called_expectation.should be_terminal
|
293
|
+
double.should be_terminal
|
294
|
+
end
|
674
295
|
end
|
675
296
|
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
297
|
+
context "when times_called_expectation's terminal? is false" do
|
298
|
+
it "returns false" do
|
299
|
+
double.definition.any_number_of_times
|
300
|
+
double.times_called_expectation.should_not be_terminal
|
301
|
+
double.should_not be_terminal
|
302
|
+
end
|
680
303
|
end
|
681
304
|
|
682
|
-
|
683
|
-
|
684
|
-
|
305
|
+
context "when there is no times_matcher" do
|
306
|
+
it "raises a DoubleDefinitionError" do
|
307
|
+
double.definition.times_matcher = nil
|
308
|
+
lambda do
|
309
|
+
double.should_not be_terminal
|
310
|
+
end.should raise_error(RR::Errors::DoubleDefinitionError)
|
311
|
+
end
|
685
312
|
end
|
686
313
|
end
|
687
314
|
|
@@ -693,14 +320,21 @@ module RR
|
|
693
320
|
end
|
694
321
|
|
695
322
|
describe "#expected_arguments" do
|
696
|
-
|
697
|
-
|
698
|
-
|
323
|
+
context "when there is an argument expectation" do
|
324
|
+
it "returns argument expectation's expected_arguments" do
|
325
|
+
double.definition.with(1, 2)
|
326
|
+
double.definition.argument_expectation.should_not be_nil
|
327
|
+
double.expected_arguments.should == [1, 2]
|
328
|
+
end
|
699
329
|
end
|
700
330
|
|
701
|
-
|
702
|
-
|
703
|
-
|
331
|
+
context "when there is no argument expectation" do
|
332
|
+
it "raises an DoubleDefinitionError" do
|
333
|
+
double.definition.argument_expectation = nil
|
334
|
+
lambda do
|
335
|
+
double.expected_arguments
|
336
|
+
end.should raise_error(Errors::DoubleDefinitionError)
|
337
|
+
end
|
704
338
|
end
|
705
339
|
end
|
706
340
|
|
@@ -710,7 +344,7 @@ module RR
|
|
710
344
|
end
|
711
345
|
|
712
346
|
it "renders the formatted name of the Double with arguments" do
|
713
|
-
double.with(1, 2)
|
347
|
+
double.definition.with(1, 2)
|
714
348
|
double.formatted_name.should == "foobar(1, 2)"
|
715
349
|
end
|
716
350
|
end
|