rr 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/README +20 -9
- data/Rakefile +1 -1
- data/examples/example_suite.rb +1 -1
- data/examples/high_level_example.rb +4 -4
- data/examples/rr/double/double_dispatching_example.rb +41 -41
- data/examples/rr/double/double_verify_example.rb +1 -1
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
- data/examples/rr/extensions/instance_methods_creator_example.rb +48 -38
- data/examples/rr/extensions/instance_methods_space_example.rb +8 -8
- data/examples/rr/rspec/rspec_adapter_example.rb +9 -9
- data/examples/rr/rspec/rspec_usage_example.rb +16 -2
- data/examples/rr/scenario_creator_example.rb +400 -0
- data/examples/rr/scenario_example.rb +19 -4
- data/examples/rr/scenario_method_proxy_example.rb +71 -0
- data/examples/rr/space/space_create_example.rb +93 -106
- data/examples/rr/space/space_example.rb +2 -2
- data/examples/rr/space/space_register_example.rb +3 -3
- data/examples/rr/space/space_reset_example.rb +11 -11
- data/examples/rr/space/space_verify_example.rb +12 -12
- data/examples/rr/test_unit/test_unit_integration_test.rb +11 -2
- data/lib/rr.rb +10 -12
- data/lib/rr/errors/scenario_definition_error.rb +6 -0
- data/lib/rr/extensions/instance_methods.rb +84 -84
- data/lib/rr/scenario.rb +18 -3
- data/lib/rr/scenario_creator.rb +233 -0
- data/lib/rr/scenario_method_proxy.rb +19 -0
- data/lib/rr/space.rb +12 -32
- metadata +7 -13
- data/examples/rr/do_not_allow_creator_example.rb +0 -111
- data/examples/rr/mock_creator_example.rb +0 -87
- data/examples/rr/mock_probe_creator_example.rb +0 -120
- data/examples/rr/stub_creator_example.rb +0 -96
- data/examples/rr/stub_probe_creator_example.rb +0 -127
- data/lib/rr/creator.rb +0 -16
- data/lib/rr/do_not_allow_creator.rb +0 -33
- data/lib/rr/mock_creator.rb +0 -26
- data/lib/rr/mock_probe_creator.rb +0 -36
- data/lib/rr/stub_creator.rb +0 -30
- data/lib/rr/stub_probe_creator.rb +0 -42
@@ -5,9 +5,11 @@ describe Scenario, :shared => true do
|
|
5
5
|
before do
|
6
6
|
@space = Space.new
|
7
7
|
@object = Object.new
|
8
|
-
@
|
9
|
-
|
10
|
-
|
8
|
+
def @object.foobar(a, b)
|
9
|
+
[b, a]
|
10
|
+
end
|
11
|
+
@double = @space.double(@object, :foobar)
|
12
|
+
@scenario = @space.scenario(@double)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
@@ -352,6 +354,19 @@ describe Scenario, "#implemented_by" do
|
|
352
354
|
end
|
353
355
|
end
|
354
356
|
|
357
|
+
describe Scenario, "#implemented_by_original_method" do
|
358
|
+
it_should_behave_like "RR::Scenario"
|
359
|
+
|
360
|
+
it "returns the scenario object" do
|
361
|
+
@scenario.implemented_by_original_method.should === @scenario
|
362
|
+
end
|
363
|
+
|
364
|
+
it "sets the implementation to the original method" do
|
365
|
+
@scenario.implemented_by_original_method
|
366
|
+
@scenario.call(1, 2).should == [2, 1]
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
355
370
|
describe Scenario, "#call implemented by a proc" do
|
356
371
|
it_should_behave_like "RR::Scenario"
|
357
372
|
|
@@ -386,7 +401,7 @@ describe Scenario, "#call implemented by a proc" do
|
|
386
401
|
|
387
402
|
it "raises ScenarioOrderError when ordered and called out of order" do
|
388
403
|
scenario1 = @scenario
|
389
|
-
scenario2 = @space.
|
404
|
+
scenario2 = @space.scenario(@double)
|
390
405
|
|
391
406
|
scenario1.with(1).returns {:return_1}.ordered.once
|
392
407
|
scenario2.with(2).returns {:return_2}.ordered.once
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "examples/example_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
describe ScenarioMethodProxy, :shared => true do
|
5
|
+
before(:each) do
|
6
|
+
@space = Space.new
|
7
|
+
@subject = Object.new
|
8
|
+
@creator = @space.scenario_creator
|
9
|
+
@creator.mock
|
10
|
+
end
|
11
|
+
|
12
|
+
it "initializes proxy with passed in creator" do
|
13
|
+
class << @proxy
|
14
|
+
attr_reader :creator
|
15
|
+
end
|
16
|
+
@proxy.creator.should === @creator
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ScenarioMethodProxy, ".new without block" do
|
21
|
+
it_should_behave_like "RR::ScenarioMethodProxy"
|
22
|
+
|
23
|
+
before do
|
24
|
+
@proxy = ScenarioMethodProxy.new(@space, @creator, @subject)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "clears out all methods from proxy" do
|
28
|
+
proxy_subclass = Class.new(ScenarioMethodProxy) do
|
29
|
+
def i_should_be_a_scenario
|
30
|
+
end
|
31
|
+
end
|
32
|
+
proxy_subclass.instance_methods.should include('i_should_be_a_scenario')
|
33
|
+
|
34
|
+
proxy = proxy_subclass.new(@space, @creator, @subject)
|
35
|
+
proxy.i_should_be_a_scenario.should be_instance_of(Scenario)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ScenarioMethodProxy, ".new with block" do
|
40
|
+
it_should_behave_like "RR::ScenarioMethodProxy"
|
41
|
+
|
42
|
+
before do
|
43
|
+
@proxy = ScenarioMethodProxy.new(@space, @creator, @subject) do |b|
|
44
|
+
b.foobar(1, 2) {:one_two}
|
45
|
+
b.foobar(1) {:one}
|
46
|
+
b.foobar.with_any_args {:default}
|
47
|
+
b.baz() {:baz_result}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "creates doubles" do
|
52
|
+
@subject.foobar(1, 2).should == :one_two
|
53
|
+
@subject.foobar(1).should == :one
|
54
|
+
@subject.foobar(:something).should == :default
|
55
|
+
@subject.baz.should == :baz_result
|
56
|
+
end
|
57
|
+
|
58
|
+
it "clears out all methods from proxy" do
|
59
|
+
proxy_subclass = Class.new(ScenarioMethodProxy) do
|
60
|
+
def i_should_be_a_scenario
|
61
|
+
end
|
62
|
+
end
|
63
|
+
proxy_subclass.instance_methods.should include('i_should_be_a_scenario')
|
64
|
+
|
65
|
+
proxy_subclass.new(@space, @creator, @subject) do |m|
|
66
|
+
m.i_should_be_a_scenario.should be_instance_of(Scenario)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "examples/example_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
describe Space, "#
|
4
|
+
describe Space, "#scenario_method_proxy", :shared => true do
|
5
5
|
it_should_behave_like "RR::Space"
|
6
6
|
|
7
7
|
before do
|
@@ -9,27 +9,50 @@ describe Space, "#mock_creator" do
|
|
9
9
|
@object = Object.new
|
10
10
|
end
|
11
11
|
|
12
|
-
it "creates a
|
13
|
-
|
14
|
-
|
15
|
-
@object.foobar(1).should == :baz
|
16
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
12
|
+
it "creates a ScenarioMethodProxy" do
|
13
|
+
proxy = @space.scenario_method_proxy(@creator, @object)
|
14
|
+
proxy.should be_instance_of(ScenarioMethodProxy)
|
17
15
|
end
|
18
16
|
|
19
|
-
it "
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
it "sets space to self" do
|
18
|
+
proxy = @space.scenario_method_proxy(@creator, @object)
|
19
|
+
class << proxy
|
20
|
+
attr_reader :space
|
21
|
+
end
|
22
|
+
proxy.space.should === @space
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets creator to passed in creator" do
|
26
|
+
proxy = @space.scenario_method_proxy(@creator, @object)
|
27
|
+
class << proxy
|
28
|
+
attr_reader :creator
|
29
|
+
end
|
30
|
+
proxy.creator.should === @creator
|
23
31
|
end
|
24
32
|
|
25
33
|
it "raises error if passed a method name and a block" do
|
26
34
|
proc do
|
27
|
-
@space.
|
35
|
+
@space.scenario_method_proxy(@creator, @object, :foobar) {}
|
28
36
|
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
29
37
|
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Space, "#scenario_method_proxy with a Mock strategy" do
|
41
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
42
|
+
|
43
|
+
before do
|
44
|
+
@creator = @space.scenario_creator
|
45
|
+
@creator.mock
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates a mock Scenario for method when passed a second argument" do
|
49
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
50
|
+
@object.foobar(1).should == :baz
|
51
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
52
|
+
end
|
30
53
|
|
31
54
|
it "uses block definition when passed a block" do
|
32
|
-
|
55
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
33
56
|
c.foobar(1) {:baz}
|
34
57
|
end
|
35
58
|
@object.foobar(1).should == :baz
|
@@ -37,36 +60,22 @@ describe Space, "#mock_creator" do
|
|
37
60
|
end
|
38
61
|
end
|
39
62
|
|
40
|
-
describe Space, "#
|
41
|
-
it_should_behave_like "RR::Space"
|
63
|
+
describe Space, "#scenario_method_proxy with a Stub strategy" do
|
64
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
42
65
|
|
43
66
|
before do
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@method_name = :foobar
|
47
|
-
end
|
48
|
-
|
49
|
-
it "creates a StubCreator" do
|
50
|
-
creator = @space.stub_creator(@object)
|
51
|
-
creator.foobar {:baz}
|
52
|
-
@object.foobar.should == :baz
|
53
|
-
@object.foobar.should == :baz
|
67
|
+
@creator = @space.scenario_creator
|
68
|
+
@creator.stub
|
54
69
|
end
|
55
70
|
|
56
71
|
it "creates a stub Scenario for method when passed a second argument" do
|
57
|
-
|
72
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
58
73
|
@object.foobar(1).should == :baz
|
59
74
|
@object.foobar(1).should == :baz
|
60
75
|
end
|
61
76
|
|
62
|
-
it "raises error if passed a method name and a block" do
|
63
|
-
proc do
|
64
|
-
@space.stub_creator(@object, :foobar) {}
|
65
|
-
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
66
|
-
end
|
67
|
-
|
68
77
|
it "uses block definition when passed a block" do
|
69
|
-
|
78
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
70
79
|
c.foobar(1) {:return_value}
|
71
80
|
c.foobar.with_any_args {:default}
|
72
81
|
c.baz(1) {:baz_value}
|
@@ -77,39 +86,25 @@ describe Space, "#stub_creator" do
|
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
80
|
-
describe Space, "#
|
81
|
-
it_should_behave_like "RR::Space"
|
89
|
+
describe Space, "#scenario_method_proxy with a Mock Probe strategy" do
|
90
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
82
91
|
|
83
92
|
before do
|
84
|
-
@
|
85
|
-
@
|
86
|
-
@method_name = :foobar
|
93
|
+
@creator = @space.scenario_creator
|
94
|
+
@creator.mock.probe
|
87
95
|
def @object.foobar(*args)
|
88
96
|
:original_foobar
|
89
97
|
end
|
90
98
|
end
|
91
99
|
|
92
|
-
it "creates a MockProbeCreator" do
|
93
|
-
creator = @space.mock_probe_creator(@object)
|
94
|
-
creator.foobar(1)
|
95
|
-
@object.foobar(1).should == :original_foobar
|
96
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
97
|
-
end
|
98
|
-
|
99
100
|
it "creates a mock probe Scenario for method when passed a second argument" do
|
100
|
-
|
101
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1)
|
101
102
|
@object.foobar(1).should == :original_foobar
|
102
103
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
103
104
|
end
|
104
105
|
|
105
|
-
it "raises error if passed a method name and a block" do
|
106
|
-
proc do
|
107
|
-
@space.mock_probe_creator(@object, :foobar) {}
|
108
|
-
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
109
|
-
end
|
110
|
-
|
111
106
|
it "uses block definition when passed a block" do
|
112
|
-
|
107
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
113
108
|
c.foobar(1)
|
114
109
|
end
|
115
110
|
@object.foobar(1).should == :original_foobar
|
@@ -117,39 +112,25 @@ describe Space, "#mock_probe_creator" do
|
|
117
112
|
end
|
118
113
|
end
|
119
114
|
|
120
|
-
describe Space, "#
|
121
|
-
it_should_behave_like "RR::Space"
|
115
|
+
describe Space, "#scenario_method_proxy with a Stub Probe strategy" do
|
116
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
122
117
|
|
123
118
|
before do
|
124
|
-
@
|
125
|
-
@
|
126
|
-
@method_name = :foobar
|
119
|
+
@creator = @space.scenario_creator
|
120
|
+
@creator.stub.probe
|
127
121
|
def @object.foobar(*args)
|
128
122
|
:original_foobar
|
129
123
|
end
|
130
124
|
end
|
131
125
|
|
132
|
-
it "creates a StubProbeCreator" do
|
133
|
-
creator = @space.stub_probe_creator(@object)
|
134
|
-
creator.foobar
|
135
|
-
@object.foobar(1).should == :original_foobar
|
136
|
-
@object.foobar(1).should == :original_foobar
|
137
|
-
end
|
138
|
-
|
139
126
|
it "creates a stub probe Scenario for method when passed a second argument" do
|
140
|
-
|
127
|
+
@space.scenario_method_proxy(@creator, @object, :foobar)
|
141
128
|
@object.foobar(1).should == :original_foobar
|
142
129
|
@object.foobar(1).should == :original_foobar
|
143
130
|
end
|
144
131
|
|
145
|
-
it "raises error if passed a method name and a block" do
|
146
|
-
proc do
|
147
|
-
@space.stub_probe_creator(@object, :foobar) {}
|
148
|
-
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
149
|
-
end
|
150
|
-
|
151
132
|
it "uses block definition when passed a block" do
|
152
|
-
|
133
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
153
134
|
c.foobar(1)
|
154
135
|
end
|
155
136
|
@object.foobar(1).should == :original_foobar
|
@@ -157,40 +138,46 @@ describe Space, "#stub_probe_creator" do
|
|
157
138
|
end
|
158
139
|
end
|
159
140
|
|
160
|
-
describe Space, "#
|
161
|
-
it_should_behave_like "RR::Space"
|
141
|
+
describe Space, "#scenario_method_proxy with a Do Not Allow strategy" do
|
142
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
162
143
|
|
163
144
|
before do
|
164
|
-
@
|
165
|
-
@
|
166
|
-
end
|
167
|
-
|
168
|
-
it "creates a MockCreator" do
|
169
|
-
creator = @space.do_not_allow_creator(@object)
|
170
|
-
creator.foobar(1)
|
171
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
145
|
+
@creator = @space.scenario_creator
|
146
|
+
@creator.do_not_call
|
172
147
|
end
|
173
148
|
|
174
149
|
it "creates a do not allow Scenario for method when passed a second argument" do
|
175
|
-
|
150
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1)
|
176
151
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
177
152
|
end
|
178
153
|
|
179
|
-
it "raises error if passed a method name and a block" do
|
180
|
-
proc do
|
181
|
-
@space.do_not_allow_creator(@object, :foobar) {}
|
182
|
-
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
183
|
-
end
|
184
|
-
|
185
154
|
it "uses block definition when passed a block" do
|
186
|
-
|
155
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
187
156
|
c.foobar(1)
|
188
157
|
end
|
189
158
|
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
190
159
|
end
|
191
160
|
end
|
192
161
|
|
193
|
-
describe Space, "#
|
162
|
+
describe Space, "#scenario_creator" do
|
163
|
+
it_should_behave_like "RR::Space"
|
164
|
+
|
165
|
+
before do
|
166
|
+
@space = Space.new
|
167
|
+
@object = Object.new
|
168
|
+
@creator = @space.scenario_creator
|
169
|
+
end
|
170
|
+
|
171
|
+
it "sets the space" do
|
172
|
+
@creator.space.should === @space
|
173
|
+
end
|
174
|
+
|
175
|
+
it "creates a ScenarioCreator" do
|
176
|
+
@creator.should be_instance_of(ScenarioCreator)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe Space, "#scenario" do
|
194
181
|
it_should_behave_like "RR::Space"
|
195
182
|
|
196
183
|
before do
|
@@ -200,17 +187,17 @@ describe Space, "#create_scenario" do
|
|
200
187
|
end
|
201
188
|
|
202
189
|
it "creates a Scenario and registers it to the double" do
|
203
|
-
double = @space.
|
190
|
+
double = @space.double(@object, @method_name)
|
204
191
|
def double.scenarios
|
205
192
|
@scenarios
|
206
193
|
end
|
207
194
|
|
208
|
-
scenario = @space.
|
195
|
+
scenario = @space.scenario(double)
|
209
196
|
double.scenarios.should include(scenario)
|
210
197
|
end
|
211
198
|
end
|
212
199
|
|
213
|
-
describe Space, "#
|
200
|
+
describe Space, "#double" do
|
214
201
|
it_should_behave_like "RR::Space"
|
215
202
|
|
216
203
|
before do
|
@@ -223,14 +210,14 @@ describe Space, "#create_double" do
|
|
223
210
|
(object1 === object2).should be_true
|
224
211
|
object1.__id__.should_not == object2.__id__
|
225
212
|
|
226
|
-
double1 = @space.
|
227
|
-
double2 = @space.
|
213
|
+
double1 = @space.double(object1, :foobar)
|
214
|
+
double2 = @space.double(object2, :foobar)
|
228
215
|
|
229
216
|
double1.should_not == double2
|
230
217
|
end
|
231
218
|
end
|
232
219
|
|
233
|
-
describe Space, "#
|
220
|
+
describe Space, "#double when double does not exist" do
|
234
221
|
it_should_behave_like "RR::Space"
|
235
222
|
|
236
223
|
before do
|
@@ -243,28 +230,28 @@ describe Space, "#create_double when double does not exist" do
|
|
243
230
|
end
|
244
231
|
|
245
232
|
it "returns double and adds double to double list when method_name is a symbol" do
|
246
|
-
double = @space.
|
247
|
-
@space.
|
233
|
+
double = @space.double(@object, @method_name)
|
234
|
+
@space.double(@object, @method_name).should === double
|
248
235
|
double.space.should === @space
|
249
236
|
double.object.should === @object
|
250
237
|
double.method_name.should === @method_name
|
251
238
|
end
|
252
239
|
|
253
240
|
it "returns double and adds double to double list when method_name is a string" do
|
254
|
-
double = @space.
|
255
|
-
@space.
|
241
|
+
double = @space.double(@object, 'foobar')
|
242
|
+
@space.double(@object, @method_name).should === double
|
256
243
|
double.space.should === @space
|
257
244
|
double.object.should === @object
|
258
245
|
double.method_name.should === @method_name
|
259
246
|
end
|
260
247
|
|
261
248
|
it "overrides the method when passing a block" do
|
262
|
-
double = @space.
|
249
|
+
double = @space.double(@object, @method_name)
|
263
250
|
@object.methods.should include("__rr__#{@method_name}")
|
264
251
|
end
|
265
252
|
end
|
266
253
|
|
267
|
-
describe Space, "#
|
254
|
+
describe Space, "#double when double exists" do
|
268
255
|
it_should_behave_like "RR::Space"
|
269
256
|
|
270
257
|
before do
|
@@ -278,14 +265,14 @@ describe Space, "#create_double when double exists" do
|
|
278
265
|
|
279
266
|
it "returns the existing double" do
|
280
267
|
original_foobar_method = @object.method(:foobar)
|
281
|
-
double = @space.
|
268
|
+
double = @space.double(@object, 'foobar')
|
282
269
|
|
283
270
|
double.original_method.should == original_foobar_method
|
284
271
|
|
285
|
-
@space.
|
272
|
+
@space.double(@object, 'foobar').should === double
|
286
273
|
|
287
274
|
double.reset
|
288
275
|
@object.foobar.should == :original_foobar
|
289
276
|
end
|
290
277
|
end
|
291
|
-
end
|
278
|
+
end
|