rr 0.4.2 → 0.4.3
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 +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
data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb
CHANGED
@@ -9,7 +9,7 @@ module Expectations
|
|
9
9
|
before do
|
10
10
|
@times = 3
|
11
11
|
@at_least = TimesCalledMatchers::AtLeastMatcher.new(times)
|
12
|
-
@expectation = TimesCalledExpectation.new(
|
12
|
+
@expectation = TimesCalledExpectation.new(double, at_least)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#verify!" do
|
@@ -3,14 +3,14 @@ require "spec/spec_helper"
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
5
|
describe TimesCalledExpectation, :shared => true do
|
6
|
-
attr_reader :space, :object, :method_name, :double_insertion, :
|
6
|
+
attr_reader :space, :object, :method_name, :double_insertion, :double, :expectation
|
7
7
|
before do
|
8
8
|
@space = Space.new
|
9
9
|
@object = Object.new
|
10
10
|
@method_name = :foobar
|
11
11
|
@double_insertion = space.double_insertion(object, method_name)
|
12
|
-
@
|
13
|
-
|
12
|
+
@double = space.double(double_insertion)
|
13
|
+
double.with_any_args
|
14
14
|
end
|
15
15
|
|
16
16
|
def raises_expectation_error(&block)
|
@@ -9,16 +9,16 @@ module RR
|
|
9
9
|
before do
|
10
10
|
@times = 0
|
11
11
|
@matcher = TimesCalledMatchers::IntegerMatcher.new(times)
|
12
|
-
@expectation = TimesCalledExpectation.new(
|
12
|
+
@expectation = TimesCalledExpectation.new(double, matcher)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#attempt!" do
|
16
|
-
it "raises error that includes the
|
16
|
+
it "raises error that includes the double" do
|
17
17
|
proc do
|
18
18
|
expectation.attempt!
|
19
19
|
end.should raise_error(
|
20
20
|
Errors::TimesCalledError,
|
21
|
-
"#{
|
21
|
+
"#{double.formatted_name}\n#{matcher.error_message(1)}"
|
22
22
|
)
|
23
23
|
end
|
24
24
|
end
|
@@ -30,7 +30,7 @@ module RR
|
|
30
30
|
expectation.verify!
|
31
31
|
end.should raise_error(
|
32
32
|
Errors::TimesCalledError,
|
33
|
-
"#{
|
33
|
+
"#{double.formatted_name}\n#{matcher.error_message(1)}"
|
34
34
|
)
|
35
35
|
end
|
36
36
|
end
|
@@ -32,9 +32,9 @@ module RR
|
|
32
32
|
|
33
33
|
it "verifies the double_insertions" do
|
34
34
|
double_insertion = RR::Space.double_insertion(@subject, @method_name)
|
35
|
-
|
35
|
+
double = RR::Space.double(double_insertion)
|
36
36
|
|
37
|
-
|
37
|
+
double.once
|
38
38
|
|
39
39
|
proc do
|
40
40
|
@fixture.verify_mocks_for_rspec
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe Space, "#
|
4
|
+
describe Space, "#double_method_proxy", :shared => true do
|
5
5
|
it_should_behave_like "RR::Space"
|
6
6
|
|
7
7
|
before do
|
@@ -10,12 +10,12 @@ module RR
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "creates a DoubleMethodProxy" do
|
13
|
-
proxy = @space.
|
13
|
+
proxy = @space.double_method_proxy(@creator, @object)
|
14
14
|
proxy.should be_instance_of(DoubleMethodProxy)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "sets space to self" do
|
18
|
-
proxy = @space.
|
18
|
+
proxy = @space.double_method_proxy(@creator, @object)
|
19
19
|
class << proxy
|
20
20
|
attr_reader :space
|
21
21
|
end
|
@@ -23,7 +23,7 @@ module RR
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "sets creator to passed in creator" do
|
26
|
-
proxy = @space.
|
26
|
+
proxy = @space.double_method_proxy(@creator, @object)
|
27
27
|
class << proxy
|
28
28
|
attr_reader :creator
|
29
29
|
end
|
@@ -32,27 +32,27 @@ module RR
|
|
32
32
|
|
33
33
|
it "raises error if passed a method name and a block" do
|
34
34
|
proc do
|
35
|
-
@space.
|
35
|
+
@space.double_method_proxy(@creator, @object, :foobar) {}
|
36
36
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe Space, "#
|
41
|
-
it_should_behave_like "RR::Space#
|
40
|
+
describe Space, "#double_method_proxy with a Mock strategy" do
|
41
|
+
it_should_behave_like "RR::Space#double_method_proxy"
|
42
42
|
|
43
43
|
before do
|
44
|
-
@creator = @space.
|
44
|
+
@creator = @space.double_creator
|
45
45
|
@creator.mock
|
46
46
|
end
|
47
47
|
|
48
48
|
it "creates a mock Double for method when passed a second argument" do
|
49
|
-
@space.
|
49
|
+
@space.double_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
50
50
|
@object.foobar(1).should == :baz
|
51
51
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "uses block definition when passed a block" do
|
55
|
-
@space.
|
55
|
+
@space.double_method_proxy(@creator, @object) do |c|
|
56
56
|
c.foobar(1) {:baz}
|
57
57
|
end
|
58
58
|
@object.foobar(1).should == :baz
|
@@ -60,22 +60,22 @@ module RR
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
describe Space, "#
|
64
|
-
it_should_behave_like "RR::Space#
|
63
|
+
describe Space, "#double_method_proxy with a Stub strategy" do
|
64
|
+
it_should_behave_like "RR::Space#double_method_proxy"
|
65
65
|
|
66
66
|
before do
|
67
|
-
@creator = @space.
|
67
|
+
@creator = @space.double_creator
|
68
68
|
@creator.stub
|
69
69
|
end
|
70
70
|
|
71
71
|
it "creates a stub Double for method when passed a second argument" do
|
72
|
-
@space.
|
72
|
+
@space.double_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
73
73
|
@object.foobar(1).should == :baz
|
74
74
|
@object.foobar(1).should == :baz
|
75
75
|
end
|
76
76
|
|
77
77
|
it "uses block definition when passed a block" do
|
78
|
-
@space.
|
78
|
+
@space.double_method_proxy(@creator, @object) do |c|
|
79
79
|
c.foobar(1) {:return_value}
|
80
80
|
c.foobar.with_any_args {:default}
|
81
81
|
c.baz(1) {:baz_value}
|
@@ -86,11 +86,11 @@ module RR
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
describe Space, "#
|
90
|
-
it_should_behave_like "RR::Space#
|
89
|
+
describe Space, "#double_method_proxy with a Mock Proxy strategy" do
|
90
|
+
it_should_behave_like "RR::Space#double_method_proxy"
|
91
91
|
|
92
92
|
before do
|
93
|
-
@creator = @space.
|
93
|
+
@creator = @space.double_creator
|
94
94
|
@creator.mock.proxy
|
95
95
|
def @object.foobar(*args)
|
96
96
|
:original_foobar
|
@@ -98,13 +98,13 @@ module RR
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it "creates a mock proxy Double for method when passed a second argument" do
|
101
|
-
@space.
|
101
|
+
@space.double_method_proxy(@creator, @object, :foobar).with(1)
|
102
102
|
@object.foobar(1).should == :original_foobar
|
103
103
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
104
104
|
end
|
105
105
|
|
106
106
|
it "uses block definition when passed a block" do
|
107
|
-
@space.
|
107
|
+
@space.double_method_proxy(@creator, @object) do |c|
|
108
108
|
c.foobar(1)
|
109
109
|
end
|
110
110
|
@object.foobar(1).should == :original_foobar
|
@@ -112,11 +112,11 @@ module RR
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe Space, "#
|
116
|
-
it_should_behave_like "RR::Space#
|
115
|
+
describe Space, "#double_method_proxy with a Stub proxy strategy" do
|
116
|
+
it_should_behave_like "RR::Space#double_method_proxy"
|
117
117
|
|
118
118
|
before do
|
119
|
-
@creator = @space.
|
119
|
+
@creator = @space.double_creator
|
120
120
|
@creator.stub.proxy
|
121
121
|
def @object.foobar(*args)
|
122
122
|
:original_foobar
|
@@ -124,13 +124,13 @@ module RR
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "creates a stub proxy Double for method when passed a second argument" do
|
127
|
-
@space.
|
127
|
+
@space.double_method_proxy(@creator, @object, :foobar)
|
128
128
|
@object.foobar(1).should == :original_foobar
|
129
129
|
@object.foobar(1).should == :original_foobar
|
130
130
|
end
|
131
131
|
|
132
132
|
it "uses block definition when passed a block" do
|
133
|
-
@space.
|
133
|
+
@space.double_method_proxy(@creator, @object) do |c|
|
134
134
|
c.foobar(1)
|
135
135
|
end
|
136
136
|
@object.foobar(1).should == :original_foobar
|
@@ -138,34 +138,34 @@ module RR
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
describe Space, "#
|
142
|
-
it_should_behave_like "RR::Space#
|
141
|
+
describe Space, "#double_method_proxy with a Do Not Allow strategy" do
|
142
|
+
it_should_behave_like "RR::Space#double_method_proxy"
|
143
143
|
|
144
144
|
before do
|
145
|
-
@creator = @space.
|
145
|
+
@creator = @space.double_creator
|
146
146
|
@creator.dont_allow
|
147
147
|
end
|
148
148
|
|
149
149
|
it "creates a do not allow Double for method when passed a second argument" do
|
150
|
-
@space.
|
150
|
+
@space.double_method_proxy(@creator, @object, :foobar).with(1)
|
151
151
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
152
152
|
end
|
153
153
|
|
154
154
|
it "uses block definition when passed a block" do
|
155
|
-
@space.
|
155
|
+
@space.double_method_proxy(@creator, @object) do |c|
|
156
156
|
c.foobar(1)
|
157
157
|
end
|
158
158
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
-
describe Space, "#
|
162
|
+
describe Space, "#double_creator" do
|
163
163
|
it_should_behave_like "RR::Space"
|
164
164
|
|
165
165
|
before do
|
166
166
|
@space = Space.new
|
167
167
|
@object = Object.new
|
168
|
-
@creator = @space.
|
168
|
+
@creator = @space.double_creator
|
169
169
|
end
|
170
170
|
|
171
171
|
it "sets the space" do
|
@@ -177,7 +177,7 @@ module RR
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
-
describe Space, "#
|
180
|
+
describe Space, "#double" do
|
181
181
|
it_should_behave_like "RR::Space"
|
182
182
|
|
183
183
|
before do
|
@@ -188,12 +188,12 @@ module RR
|
|
188
188
|
|
189
189
|
it "creates a Double and registers it to the double_insertion" do
|
190
190
|
double_insertion = @space.double_insertion(@object, @method_name)
|
191
|
-
def double_insertion.
|
192
|
-
@
|
191
|
+
def double_insertion.doubles
|
192
|
+
@doubles
|
193
193
|
end
|
194
194
|
|
195
|
-
|
196
|
-
double_insertion.
|
195
|
+
double = @space.double(double_insertion)
|
196
|
+
double_insertion.doubles.should include(double)
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe Space, "#
|
4
|
+
describe Space, "#register_ordered_double" do
|
5
5
|
it_should_behave_like "RR::Space"
|
6
6
|
|
7
7
|
before(:each) do
|
@@ -17,16 +17,16 @@ module RR
|
|
17
17
|
Space.instance = @original_space
|
18
18
|
end
|
19
19
|
|
20
|
-
it "adds the ordered
|
21
|
-
|
20
|
+
it "adds the ordered double to the ordered_doubles collection" do
|
21
|
+
double1 = @space.double(@double_insertion)
|
22
22
|
|
23
|
-
@space.
|
24
|
-
@space.
|
25
|
-
@space.
|
23
|
+
@space.ordered_doubles.should == []
|
24
|
+
@space.register_ordered_double double1
|
25
|
+
@space.ordered_doubles.should == [double1]
|
26
26
|
|
27
|
-
|
28
|
-
@space.
|
29
|
-
@space.
|
27
|
+
double2 = @space.double(@double_insertion)
|
28
|
+
@space.register_ordered_double double2
|
29
|
+
@space.ordered_doubles.should == [double1, double2]
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -11,20 +11,20 @@ module RR
|
|
11
11
|
@method_name = :foobar
|
12
12
|
end
|
13
13
|
|
14
|
-
it "removes the ordered
|
14
|
+
it "removes the ordered doubles" do
|
15
15
|
double1 = @space.double_insertion(@object1, :foobar1)
|
16
16
|
double2 = @space.double_insertion(@object1, :foobar2)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
double1 = @space.double(double1)
|
19
|
+
double2 = @space.double(double2)
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
double1.ordered
|
22
|
+
double2.ordered
|
23
23
|
|
24
|
-
@space.
|
24
|
+
@space.ordered_doubles.should_not be_empty
|
25
25
|
|
26
26
|
@space.reset
|
27
|
-
@space.
|
27
|
+
@space.ordered_doubles.should be_empty
|
28
28
|
end
|
29
29
|
|
30
30
|
it "resets all double_insertions" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe Space, "#
|
4
|
+
describe Space, "#verify_ordered_double", :shared => true do
|
5
5
|
before do
|
6
6
|
@space = Space.new
|
7
7
|
@object = Object.new
|
@@ -10,14 +10,14 @@ module RR
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raises an error when Double is NonTerminal" do
|
13
|
-
|
14
|
-
@space.
|
13
|
+
double = @space.double(@double_insertion)
|
14
|
+
@space.register_ordered_double(double)
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
double.any_number_of_times
|
17
|
+
double.should_not be_terminal
|
18
18
|
|
19
19
|
proc do
|
20
|
-
@space.
|
20
|
+
@space.verify_ordered_double(double)
|
21
21
|
end.should raise_error(
|
22
22
|
Errors::DoubleOrderError,
|
23
23
|
"Ordered Doubles cannot have a NonTerminal TimesCalledExpectation"
|
@@ -127,42 +127,42 @@ module RR
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
describe "#
|
131
|
-
it_should_behave_like "RR::Space#
|
130
|
+
describe "#verify_ordered_double where the passed in double is at the front of the queue" do
|
131
|
+
it_should_behave_like "RR::Space#verify_ordered_double"
|
132
132
|
|
133
|
-
it "keeps the
|
134
|
-
|
135
|
-
@space.
|
133
|
+
it "keeps the double when times called is not verified" do
|
134
|
+
double = @space.double(@double_insertion)
|
135
|
+
@space.register_ordered_double(double)
|
136
136
|
|
137
|
-
|
138
|
-
|
137
|
+
double.twice
|
138
|
+
double.should be_attempt
|
139
139
|
|
140
|
-
@space.
|
141
|
-
@space.
|
140
|
+
@space.verify_ordered_double(double)
|
141
|
+
@space.ordered_doubles.should include(double)
|
142
142
|
end
|
143
143
|
|
144
|
-
it "removes the
|
145
|
-
|
146
|
-
@space.
|
144
|
+
it "removes the double when times called expectation should no longer be attempted" do
|
145
|
+
double = @space.double(@double_insertion)
|
146
|
+
@space.register_ordered_double(double)
|
147
147
|
|
148
|
-
|
148
|
+
double.with(1).once
|
149
149
|
@object.foobar(1)
|
150
|
-
|
150
|
+
double.should_not be_attempt
|
151
151
|
|
152
|
-
@space.
|
153
|
-
@space.
|
152
|
+
@space.verify_ordered_double(double)
|
153
|
+
@space.ordered_doubles.should_not include(double)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
describe "#
|
158
|
-
it_should_behave_like "RR::Space#
|
157
|
+
describe "#verify_ordered_double where the passed in double is not at the front of the queue" do
|
158
|
+
it_should_behave_like "RR::Space#verify_ordered_double"
|
159
159
|
|
160
160
|
it "raises error" do
|
161
|
-
|
162
|
-
|
161
|
+
first_double = double
|
162
|
+
second_double = double
|
163
163
|
|
164
164
|
proc do
|
165
|
-
@space.
|
165
|
+
@space.verify_ordered_double(second_double)
|
166
166
|
end.should raise_error(
|
167
167
|
Errors::DoubleOrderError,
|
168
168
|
"foobar() called out of order in list\n" <<
|
@@ -171,10 +171,10 @@ module RR
|
|
171
171
|
)
|
172
172
|
end
|
173
173
|
|
174
|
-
def
|
175
|
-
|
176
|
-
@space.
|
177
|
-
|
174
|
+
def double
|
175
|
+
double_definition = @space.double(@double_insertion).once
|
176
|
+
@space.register_ordered_double(double_definition.double)
|
177
|
+
double_definition.double
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|