rr 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.3.10
2
+ - Fixed [#13139] Blocks added to proxy sets the return_value and not the after_call callback
3
+
1
4
  * 0.3.9
2
5
  - Alias probe to proxy
3
6
 
data/README CHANGED
@@ -22,14 +22,14 @@ http://xunitpatterns.com/Test%20Stub.html
22
22
  jane = User.new
23
23
  stub(User).find('42') {jane}
24
24
 
25
- == Mock Probes
25
+ == Mock Proxies/Probes
26
26
  Add verifications that a method was called while actually calling it.
27
27
  The following example verifies render partial will be called and
28
28
  renders the partial.
29
29
 
30
30
  view = controller.template
31
- mock.probe(view).render(:partial => "right_navigation")
32
- mock.probe(view).render(:partial => "user_info") do |html|
31
+ mock.proxy(view).render(:partial => "right_navigation")
32
+ mock.proxy(view).render(:partial => "user_info") do |html|
33
33
  html.should include("John Doe")
34
34
  "Different html"
35
35
  end
@@ -40,21 +40,21 @@ This technique is also useful for verifying that you are mocking exists and
40
40
  functions proberly, thereby testing you interface.
41
41
  For example, using ActiveRecord:
42
42
 
43
- mock.probe(User).find('5') do |user|
44
- mock.probe(user).projects do |projects|
43
+ mock.proxy(User).find('5') do |user|
44
+ mock.proxy(user).projects do |projects|
45
45
  projects[0..3]
46
46
  end
47
47
  mock(user).valid? {false}
48
48
  user
49
49
  end
50
50
 
51
- == Stub Probes
51
+ == Stub Proxy/Probes
52
52
  Intercept the return value of a method call.
53
53
  The following example verifies render partial will be called and
54
54
  renders the partial.
55
55
 
56
56
  view = controller.template
57
- stub.probe(view).render(:partial => "user_info") do |html|
57
+ stub.proxy(view).render(:partial => "user_info") do |html|
58
58
  html.should include("Joe Smith")
59
59
  html
60
60
  end
data/Rakefile CHANGED
@@ -15,6 +15,7 @@ task(:spec) do
15
15
  run_suite
16
16
  end
17
17
 
18
+ desc "Copies the trunk to a tag with the name of the current release"
18
19
  task(:tag_release) do
19
20
  tag_release
20
21
  end
@@ -25,7 +26,7 @@ def run_suite
25
26
  end
26
27
 
27
28
  PKG_NAME = "rr"
28
- PKG_VERSION = "0.3.9"
29
+ PKG_VERSION = "0.3.10"
29
30
  PKG_FILES = FileList[
30
31
  '[A-Z]*',
31
32
  '*.rb',
@@ -0,0 +1,31 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ class CoreExampleSuite
5
+ def run
6
+ options = ::Spec::Runner::OptionParser.new.parse(ARGV.dup, STDERR, STDOUT, false)
7
+ options.configure
8
+ $behaviour_runner = options.create_behaviour_runner
9
+
10
+ require_specs
11
+
12
+ puts "Running Rspec Example Suite"
13
+ $behaviour_runner.run(ARGV, false)
14
+ end
15
+
16
+ def require_specs
17
+ exclusions = []
18
+ exclusions << "rspec/"
19
+ exclusions << "test_unit/"
20
+
21
+ Dir["#{File.dirname(__FILE__)}/**/*_example.rb"].each do |file|
22
+ unless exclusions.any? {|match| file.include?(match)}
23
+ require file
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ if $0 == __FILE__
30
+ CoreExampleSuite.new.run
31
+ end
@@ -1,30 +1,12 @@
1
- require "rubygems"
2
- require "spec"
3
-
4
1
  class ExampleSuite
5
2
  def run
6
- options = ::Spec::Runner::OptionParser.new.parse(ARGV.dup, STDERR, STDOUT, false)
7
- $behaviour_runner = options.create_behaviour_runner
8
-
9
- require_specs
10
-
11
- puts "Running Example Suite"
12
- $behaviour_runner.run(ARGV, false)
13
-
3
+ run_core_examples
14
4
  run_rspec_examples
15
5
  run_test_unit_examples
16
6
  end
17
7
 
18
- def require_specs
19
- exclusions = []
20
- exclusions << "rspec/"
21
- exclusions << "test_unit/"
22
-
23
- Dir["#{dir}/**/*_example.rb"].each do |file|
24
- unless exclusions.any? {|match| file.include?(match)}
25
- require file
26
- end
27
- end
8
+ def run_core_examples
9
+ system("ruby #{dir}/core_example_suite.rb") || raise("Core suite Failed")
28
10
  end
29
11
 
30
12
  def run_rspec_examples
@@ -2,16 +2,6 @@ require "examples/example_helper"
2
2
 
3
3
  module RR
4
4
  module Expectations
5
- describe TimesCalledExpectation, :shared => true do
6
- before do
7
- @space = Space.new
8
- @object = Object.new
9
- @double = @space.double(@object, :foobar)
10
- @scenario = @space.scenario(@double)
11
- @scenario.with(1, 2)
12
- end
13
- end
14
-
15
5
  describe TimesCalledExpectation, " with failure", :shared => true do
16
6
  it_should_behave_like "RR::Expectations::TimesCalledExpectation"
17
7
 
@@ -1,18 +1,20 @@
1
+ require "examples/example_helper"
2
+
1
3
  module RR
2
4
  module Expectations
3
- describe TimesCalledExpectation, :shared => true do
4
- before do
5
- @space = Space.new
6
- @object = Object.new
7
- @method_name = :foobar
8
- @double = @space.double(@object, @method_name)
9
- @scenario = @space.scenario(@double)
10
- @scenario.with_any_args
11
- end
5
+ describe TimesCalledExpectation, :shared => true do
6
+ before do
7
+ @space = Space.new
8
+ @object = Object.new
9
+ @method_name = :foobar
10
+ @double = @space.double(@object, @method_name)
11
+ @scenario = @space.scenario(@double)
12
+ @scenario.with_any_args
13
+ end
12
14
 
13
- def raises_expectation_error(&block)
14
- proc {block.call}.should raise_error(Errors::TimesCalledError)
15
- end
15
+ def raises_expectation_error(&block)
16
+ proc {block.call}.should raise_error(Errors::TimesCalledError)
16
17
  end
17
18
  end
18
19
  end
20
+ end
@@ -80,6 +80,11 @@ describe ScenarioCreator, "#mock" do
80
80
  )
81
81
  end
82
82
 
83
+ it "sets up the ScenarioDefinition to be in returns block_callback_strategy" do
84
+ scenario = @creator.mock(@subject, :foobar)
85
+ scenario.block_callback_strategy.should == :returns
86
+ end
87
+
83
88
  def create_scenario_with_method_name(scenario)
84
89
  scenario.with(1, 2) {:baz}
85
90
  scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
@@ -114,6 +119,11 @@ describe ScenarioCreator, "#stub" do
114
119
  should create_scenario_with_method_name(@creator.stub(@subject, :foobar))
115
120
  end
116
121
 
122
+ it "sets up the ScenarioDefinition to be in returns block_callback_strategy" do
123
+ scenario = @creator.stub(@subject, :foobar)
124
+ scenario.block_callback_strategy.should == :returns
125
+ end
126
+
117
127
  def create_scenario_with_method_name(scenario)
118
128
  scenario.with(1, 2) {:baz}
119
129
  scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
@@ -255,6 +265,20 @@ describe ScenarioCreator, "(#probe or #proxy) and #stub" do
255
265
  scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
256
266
  @subject.foobar(1, 2).should == :baz
257
267
  end
268
+
269
+ it "sets up the ScenarioDefinition to be in after_call block_callback_strategy" do
270
+ def @subject.foobar
271
+ :original_implementation_value
272
+ end
273
+
274
+ args = nil
275
+ scenario = @creator.stub.proxy(@subject, :foobar).with() do |*args|
276
+ args = args
277
+ end
278
+ @subject.foobar
279
+ args.should == [:original_implementation_value]
280
+ scenario.block_callback_strategy.should == :after_call
281
+ end
258
282
  end
259
283
 
260
284
  describe ScenarioCreator, "#instance_of" do
@@ -5,16 +5,35 @@ describe ScenarioDefinition, :shared => true do
5
5
  before do
6
6
  @space = Space.new
7
7
  @object = Object.new
8
- def @object.foobar(a, b)
9
- [b, a]
10
- end
8
+ add_original_method
11
9
  @double = @space.double(@object, :foobar)
12
10
  @scenario = @space.scenario(@double)
13
11
  @definition = @scenario.definition
14
12
  end
13
+
14
+ def add_original_method
15
+ def @object.foobar(a, b)
16
+ :original_return_value
17
+ end
18
+ end
19
+ end
20
+
21
+ describe ScenarioDefinition, " with returns block_callback_strategy", :shared => true do
22
+ before do
23
+ @definition.returns_block_callback_strategy!
24
+ create_definition
25
+ end
26
+ end
27
+
28
+ describe ScenarioDefinition, " with after_call block_callback_strategy", :shared => true do
29
+ before do
30
+ @definition.implemented_by_original_method
31
+ @definition.after_call_block_callback_strategy!
32
+ create_definition
33
+ end
15
34
  end
16
35
 
17
- describe ScenarioDefinition, "#with" do
36
+ describe ScenarioDefinition, "#with", :shared => true do
18
37
  it_should_behave_like "RR::ScenarioDefinition"
19
38
 
20
39
  it "returns ScenarioDefinition" do
@@ -22,23 +41,44 @@ describe ScenarioDefinition, "#with" do
22
41
  end
23
42
 
24
43
  it "sets an ArgumentEqualityExpectation" do
25
- @definition.with(1)
26
- @definition.should be_exact_match(1)
44
+ @definition.should be_exact_match(1, 2)
27
45
  @definition.should_not be_exact_match(2)
28
46
  end
29
47
 
48
+ def create_definition
49
+ actual_args = nil
50
+ @definition.with(1, 2) do |*args|
51
+ actual_args = args
52
+ :new_return_value
53
+ end
54
+ @object.foobar(1, 2)
55
+ @return_value = @object.foobar(1, 2)
56
+ @args = actual_args
57
+ end
58
+ end
59
+
60
+ describe ScenarioDefinition, "#with with returns block_callback_strategy" do
61
+ it_should_behave_like "RR::ScenarioDefinition#with"
62
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
63
+
30
64
  it "sets return value when block passed in" do
31
- @definition.with(1) {:return_value}
32
- @object.foobar(1).should == :return_value
65
+ @return_value.should == :new_return_value
66
+ @args.should == [1, 2]
33
67
  end
34
68
  end
35
69
 
36
- describe ScenarioDefinition, "#with_any_args" do
37
- it_should_behave_like "RR::ScenarioDefinition"
70
+ describe ScenarioDefinition, "#with with after_call block_callback_strategy" do
71
+ it_should_behave_like "RR::ScenarioDefinition#with"
72
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
38
73
 
39
- before do
40
- @definition.with_any_args {:return_value}
74
+ it "sets return value when block passed in" do
75
+ @return_value.should == :new_return_value
76
+ @args.should == [:original_return_value]
41
77
  end
78
+ end
79
+
80
+ describe ScenarioDefinition, "#with_any_args", :shared => true do
81
+ it_should_behave_like "RR::ScenarioDefinition"
42
82
 
43
83
  it "returns ScenarioDefinition" do
44
84
  @definition.with_no_args.should === @definition
@@ -49,17 +89,39 @@ describe ScenarioDefinition, "#with_any_args" do
49
89
  @definition.should be_wildcard_match(1)
50
90
  end
51
91
 
92
+ def create_definition
93
+ actual_args = nil
94
+ @definition.with_any_args do |*args|
95
+ actual_args = args
96
+ :new_return_value
97
+ end
98
+ @return_value = @object.foobar(1, 2)
99
+ @args = actual_args
100
+ end
101
+ end
102
+
103
+ describe ScenarioDefinition, "#with_any_args with returns block_callback_strategy" do
104
+ it_should_behave_like "RR::ScenarioDefinition#with_any_args"
105
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
106
+
52
107
  it "sets return value when block passed in" do
53
- @object.foobar(:anything).should == :return_value
108
+ @return_value.should == :new_return_value
109
+ @args.should == [1, 2]
54
110
  end
55
111
  end
56
112
 
57
- describe ScenarioDefinition, "#with_no_args" do
58
- it_should_behave_like "RR::ScenarioDefinition"
113
+ describe ScenarioDefinition, "#with_any_args with after_call block_callback_strategy" do
114
+ it_should_behave_like "RR::ScenarioDefinition#with_any_args"
115
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
59
116
 
60
- before do
61
- @definition.with_no_args {:return_value}
117
+ it "sets return value when block passed in" do
118
+ @return_value.should == :new_return_value
119
+ @args.should == [:original_return_value]
62
120
  end
121
+ end
122
+
123
+ describe ScenarioDefinition, "#with_no_args", :shared => true do
124
+ it_should_behave_like "RR::ScenarioDefinition"
63
125
 
64
126
  it "returns ScenarioDefinition" do
65
127
  @definition.with_no_args.should === @definition
@@ -69,8 +131,40 @@ describe ScenarioDefinition, "#with_no_args" do
69
131
  @definition.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
70
132
  end
71
133
 
134
+ def add_original_method
135
+ def @object.foobar()
136
+ :original_return_value
137
+ end
138
+ end
139
+
140
+ def create_definition
141
+ actual_args = nil
142
+ @definition.with_no_args do |*args|
143
+ actual_args = args
144
+ :new_return_value
145
+ end
146
+ @return_value = @object.foobar
147
+ @args = actual_args
148
+ end
149
+ end
150
+
151
+ describe ScenarioDefinition, "#with_no_args with returns block_callback_strategy" do
152
+ it_should_behave_like "RR::ScenarioDefinition#with_no_args"
153
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
154
+
155
+ it "sets return value when block passed in" do
156
+ @return_value.should == :new_return_value
157
+ @args.should == []
158
+ end
159
+ end
160
+
161
+ describe ScenarioDefinition, "#with_no_args with after_call block_callback_strategy" do
162
+ it_should_behave_like "RR::ScenarioDefinition#with_no_args"
163
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
164
+
72
165
  it "sets return value when block passed in" do
73
- @object.foobar().should == :return_value
166
+ @return_value.should == :new_return_value
167
+ @args.should == [:original_return_value]
74
168
  end
75
169
  end
76
170
 
@@ -93,7 +187,7 @@ describe ScenarioDefinition, "#never" do
93
187
  end
94
188
  end
95
189
 
96
- describe ScenarioDefinition, "#once" do
190
+ describe ScenarioDefinition, "#once", :shared => true do
97
191
  it_should_behave_like "RR::ScenarioDefinition"
98
192
 
99
193
  it "returns ScenarioDefinition" do
@@ -101,18 +195,41 @@ describe ScenarioDefinition, "#once" do
101
195
  end
102
196
 
103
197
  it "sets up a Times Called Expectation with 1" do
104
- @definition.once.with_any_args
105
- @object.foobar
106
198
  proc {@object.foobar}.should raise_error(Errors::TimesCalledError)
107
199
  end
108
200
 
201
+ def create_definition
202
+ actual_args = nil
203
+ @definition.with_any_args.once do |*args|
204
+ actual_args = args
205
+ :new_return_value
206
+ end
207
+ @return_value = @object.foobar(1, 2)
208
+ @args = actual_args
209
+ end
210
+ end
211
+
212
+ describe ScenarioDefinition, "#once with returns block_callback_strategy" do
213
+ it_should_behave_like "RR::ScenarioDefinition#once"
214
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
215
+
216
+ it "sets return value when block passed in" do
217
+ @return_value.should == :new_return_value
218
+ @args.should == [1, 2]
219
+ end
220
+ end
221
+
222
+ describe ScenarioDefinition, "#once with after_call block_callback_strategy" do
223
+ it_should_behave_like "RR::ScenarioDefinition#once"
224
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
225
+
109
226
  it "sets return value when block passed in" do
110
- @definition.with_any_args.once {:return_value}
111
- @object.foobar.should == :return_value
227
+ @return_value.should == :new_return_value
228
+ @args.should == [:original_return_value]
112
229
  end
113
230
  end
114
231
 
115
- describe ScenarioDefinition, "#twice" do
232
+ describe ScenarioDefinition, "#twice", :shared => true do
116
233
  it_should_behave_like "RR::ScenarioDefinition"
117
234
 
118
235
  it "returns ScenarioDefinition" do
@@ -121,18 +238,42 @@ describe ScenarioDefinition, "#twice" do
121
238
 
122
239
  it "sets up a Times Called Expectation with 2" do
123
240
  @definition.twice.with_any_args
124
- @object.foobar
125
- @object.foobar
126
- proc {@object.foobar}.should raise_error(Errors::TimesCalledError)
241
+ proc {@object.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
127
242
  end
128
243
 
244
+ def create_definition
245
+ actual_args = nil
246
+ @definition.with_any_args.twice do |*args|
247
+ actual_args = args
248
+ :new_return_value
249
+ end
250
+ @object.foobar(1, 2)
251
+ @return_value = @object.foobar(1, 2)
252
+ @args = actual_args
253
+ end
254
+ end
255
+
256
+ describe ScenarioDefinition, "#twice with returns block_callback_strategy" do
257
+ it_should_behave_like "RR::ScenarioDefinition#twice"
258
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
259
+
129
260
  it "sets return value when block passed in" do
130
- @definition.with_any_args.twice {:return_value}
131
- @object.foobar.should == :return_value
261
+ @return_value.should == :new_return_value
262
+ @args.should == [1, 2]
132
263
  end
133
264
  end
134
265
 
135
- describe ScenarioDefinition, "#at_least" do
266
+ describe ScenarioDefinition, "#twice with after_call block_callback_strategy" do
267
+ it_should_behave_like "RR::ScenarioDefinition#twice"
268
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
269
+
270
+ it "sets return value when block passed in" do
271
+ @return_value.should == :new_return_value
272
+ @args.should == [:original_return_value]
273
+ end
274
+ end
275
+
276
+ describe ScenarioDefinition, "#at_least", :shared => true do
136
277
  it_should_behave_like "RR::ScenarioDefinition"
137
278
 
138
279
  it "returns ScenarioDefinition" do
@@ -140,17 +281,42 @@ describe ScenarioDefinition, "#at_least" do
140
281
  end
141
282
 
142
283
  it "sets up a Times Called Expectation with 1" do
143
- @definition.at_least(2)
144
284
  @definition.times_matcher.should == TimesCalledMatchers::AtLeastMatcher.new(2)
145
285
  end
146
286
 
287
+ def create_definition
288
+ actual_args = nil
289
+ @definition.with_any_args.at_least(2) do |*args|
290
+ actual_args = args
291
+ :new_return_value
292
+ end
293
+ @object.foobar(1, 2)
294
+ @return_value = @object.foobar(1, 2)
295
+ @args = actual_args
296
+ end
297
+ end
298
+
299
+ describe ScenarioDefinition, "#at_least with returns block_callback_strategy" do
300
+ it_should_behave_like "RR::ScenarioDefinition#at_least"
301
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
302
+
303
+ it "sets return value when block passed in" do
304
+ @return_value.should == :new_return_value
305
+ @args.should == [1, 2]
306
+ end
307
+ end
308
+
309
+ describe ScenarioDefinition, "#at_least with after_call block_callback_strategy" do
310
+ it_should_behave_like "RR::ScenarioDefinition#at_least"
311
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
312
+
147
313
  it "sets return value when block passed in" do
148
- @definition.with_any_args.at_least(2) {:return_value}
149
- @object.foobar.should == :return_value
314
+ @return_value.should == :new_return_value
315
+ @args.should == [:original_return_value]
150
316
  end
151
317
  end
152
318
 
153
- describe ScenarioDefinition, "#at_most" do
319
+ describe ScenarioDefinition, "#at_most", :shared => true do
154
320
  it_should_behave_like "RR::ScenarioDefinition"
155
321
 
156
322
  it "returns ScenarioDefinition" do
@@ -158,9 +324,6 @@ describe ScenarioDefinition, "#at_most" do
158
324
  end
159
325
 
160
326
  it "sets up a Times Called Expectation with 1" do
161
- @definition.at_most(2).with_any_args
162
- @object.foobar
163
- @object.foobar
164
327
  proc do
165
328
  @object.foobar
166
329
  end.should raise_error(
@@ -169,13 +332,39 @@ describe ScenarioDefinition, "#at_most" do
169
332
  )
170
333
  end
171
334
 
335
+ def create_definition
336
+ actual_args = nil
337
+ @definition.with_any_args.at_most(2) do |*args|
338
+ actual_args = args
339
+ :new_return_value
340
+ end
341
+ @object.foobar(1, 2)
342
+ @return_value = @object.foobar(1, 2)
343
+ @args = actual_args
344
+ end
345
+ end
346
+
347
+ describe ScenarioDefinition, "#at_most with returns block_callback_strategy" do
348
+ it_should_behave_like "RR::ScenarioDefinition#at_most"
349
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
350
+
351
+ it "sets return value when block passed in" do
352
+ @return_value.should == :new_return_value
353
+ @args.should == [1, 2]
354
+ end
355
+ end
356
+
357
+ describe ScenarioDefinition, "#at_most with after_call block_callback_strategy" do
358
+ it_should_behave_like "RR::ScenarioDefinition#at_most"
359
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
360
+
172
361
  it "sets return value when block passed in" do
173
- @definition.with_any_args.at_most(2) {:return_value}
174
- @object.foobar.should == :return_value
362
+ @return_value.should == :new_return_value
363
+ @args.should == [:original_return_value]
175
364
  end
176
365
  end
177
366
 
178
- describe ScenarioDefinition, "#times" do
367
+ describe ScenarioDefinition, "#times", :shared => true do
179
368
  it_should_behave_like "RR::ScenarioDefinition"
180
369
 
181
370
  it "returns ScenarioDefinition" do
@@ -183,20 +372,43 @@ describe ScenarioDefinition, "#times" do
183
372
  end
184
373
 
185
374
  it "sets up a Times Called Expectation with passed in times" do
186
- @definition.times(3).with_any_args
187
- @object.foobar
188
- @object.foobar
189
- @object.foobar
190
- proc {@object.foobar}.should raise_error(Errors::TimesCalledError)
375
+ proc {@object.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
376
+ end
377
+
378
+ def create_definition
379
+ actual_args = nil
380
+ @definition.with(1, 2).times(3) do |*args|
381
+ actual_args = args
382
+ :new_return_value
383
+ end
384
+ @object.foobar(1, 2)
385
+ @object.foobar(1, 2)
386
+ @return_value = @object.foobar(1, 2)
387
+ @args = actual_args
388
+ end
389
+ end
390
+
391
+ describe ScenarioDefinition, "#times with returns block_callback_strategy" do
392
+ it_should_behave_like "RR::ScenarioDefinition#times"
393
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
394
+
395
+ it "sets return value when block passed in" do
396
+ @return_value.should == :new_return_value
397
+ @args.should == [1, 2]
191
398
  end
399
+ end
400
+
401
+ describe ScenarioDefinition, "#times with after_call block_callback_strategy" do
402
+ it_should_behave_like "RR::ScenarioDefinition#times"
403
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
192
404
 
193
405
  it "sets return value when block passed in" do
194
- @definition.with_any_args.times(3) {:return_value}
195
- @object.foobar.should == :return_value
406
+ @return_value.should == :new_return_value
407
+ @args.should == [:original_return_value]
196
408
  end
197
409
  end
198
410
 
199
- describe ScenarioDefinition, "#any_number_of_times" do
411
+ describe ScenarioDefinition, "#any_number_of_times", :shared => true do
200
412
  it_should_behave_like "RR::ScenarioDefinition"
201
413
 
202
414
  it "returns ScenarioDefinition" do
@@ -204,17 +416,42 @@ describe ScenarioDefinition, "#any_number_of_times" do
204
416
  end
205
417
 
206
418
  it "sets up a Times Called Expectation with AnyTimes matcher" do
207
- @definition.any_number_of_times
208
419
  @definition.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
209
420
  end
210
421
 
422
+ def create_definition
423
+ actual_args = nil
424
+ @definition.with(1, 2).any_number_of_times do |*args|
425
+ actual_args = args
426
+ :new_return_value
427
+ end
428
+ @object.foobar(1, 2)
429
+ @return_value = @object.foobar(1, 2)
430
+ @args = actual_args
431
+ end
432
+ end
433
+
434
+ describe ScenarioDefinition, "#any_number_of_times with returns block_callback_strategy" do
435
+ it_should_behave_like "RR::ScenarioDefinition#any_number_of_times"
436
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
437
+
438
+ it "sets return value when block passed in" do
439
+ @return_value.should == :new_return_value
440
+ @args.should == [1, 2]
441
+ end
442
+ end
443
+
444
+ describe ScenarioDefinition, "#any_number_of_times with after_call block_callback_strategy" do
445
+ it_should_behave_like "RR::ScenarioDefinition#any_number_of_times"
446
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
447
+
211
448
  it "sets return value when block passed in" do
212
- @definition.with_any_args.any_number_of_times {:return_value}
213
- @object.foobar.should == :return_value
449
+ @return_value.should == :new_return_value
450
+ @args.should == [:original_return_value]
214
451
  end
215
452
  end
216
453
 
217
- describe ScenarioDefinition, "#ordered" do
454
+ describe ScenarioDefinition, "#ordered", :shared => true do
218
455
  it_should_behave_like "RR::ScenarioDefinition"
219
456
 
220
457
  it "adds itself to the ordered scenarios list" do
@@ -223,21 +460,14 @@ describe ScenarioDefinition, "#ordered" do
223
460
  end
224
461
 
225
462
  it "does not double add itself" do
226
- @definition.ordered
227
463
  @definition.ordered
228
464
  @space.ordered_scenarios.should == [@scenario]
229
465
  end
230
466
 
231
467
  it "sets ordered? to true" do
232
- @definition.ordered
233
468
  @definition.should be_ordered
234
469
  end
235
470
 
236
- it "sets return value when block passed in" do
237
- @definition.with_any_args.once.ordered {:return_value}
238
- @object.foobar.should == :return_value
239
- end
240
-
241
471
  it "raises error when there is no Scenario" do
242
472
  @definition.scenario = nil
243
473
  proc do
@@ -249,6 +479,36 @@ describe ScenarioDefinition, "#ordered" do
249
479
  "probe the class's #new method instead."
250
480
  )
251
481
  end
482
+
483
+ def create_definition
484
+ actual_args = nil
485
+ @definition.with(1, 2).once.ordered do |*args|
486
+ actual_args = args
487
+ :new_return_value
488
+ end
489
+ @return_value = @object.foobar(1, 2)
490
+ @args = actual_args
491
+ end
492
+ end
493
+
494
+ describe ScenarioDefinition, "#ordered with returns block_callback_strategy" do
495
+ it_should_behave_like "RR::ScenarioDefinition#ordered"
496
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
497
+
498
+ it "sets return value when block passed in" do
499
+ @return_value.should == :new_return_value
500
+ @args.should == [1, 2]
501
+ end
502
+ end
503
+
504
+ describe ScenarioDefinition, "#ordered with after_call block_callback_strategy" do
505
+ it_should_behave_like "RR::ScenarioDefinition#ordered"
506
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
507
+
508
+ it "sets return value when block passed in" do
509
+ @return_value.should == :new_return_value
510
+ @args.should == [:original_return_value]
511
+ end
252
512
  end
253
513
 
254
514
  describe ScenarioDefinition, "#ordered?" do
@@ -259,31 +519,52 @@ describe ScenarioDefinition, "#ordered?" do
259
519
  end
260
520
  end
261
521
 
262
- describe ScenarioDefinition, "#yields" do
522
+ describe ScenarioDefinition, "#yields", :shared => true do
263
523
  it_should_behave_like "RR::ScenarioDefinition"
264
524
 
265
525
  it "returns ScenarioDefinition" do
266
526
  @definition.yields(:baz).should === @definition
267
527
  end
268
528
 
269
- it "yields the passed in argument to the call block when there is no returns value set" do
270
- @definition.with_any_args.yields(:baz)
529
+ it "yields the passed in argument to the call block when there is a no returns value set" do
530
+ @passed_in_block_arg.should == :baz
531
+ end
532
+
533
+ def create_definition
534
+ actual_args = nil
535
+ @definition.with(1, 2).once.yields(:baz) do |*args|
536
+ actual_args = args
537
+ :new_return_value
538
+ end
271
539
  passed_in_block_arg = nil
272
- @object.foobar {|arg| passed_in_block_arg = arg}.should == nil
273
- passed_in_block_arg.should == :baz
540
+ @return_value = @object.foobar(1, 2) do |arg|
541
+ passed_in_block_arg = arg
542
+ end
543
+ @passed_in_block_arg = passed_in_block_arg
544
+
545
+ @args = actual_args
274
546
  end
547
+ end
275
548
 
276
- it "yields the passed in argument to the call block when there is a no returns value set" do
277
- @definition.with_any_args.yields(:baz).returns(:return_value)
549
+ describe ScenarioDefinition, "#yields with returns block_callback_strategy" do
550
+ it_should_behave_like "RR::ScenarioDefinition#yields"
551
+ it_should_behave_like "RR::ScenarioDefinition with returns block_callback_strategy"
278
552
 
279
- passed_in_block_arg = nil
280
- @object.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
281
- passed_in_block_arg.should == :baz
553
+ it "sets return value when block passed in" do
554
+ @return_value.should == :new_return_value
555
+ @args.length.should == 3
556
+ @args[0..1].should == [1, 2]
557
+ @args[2].should be_instance_of(Proc)
282
558
  end
559
+ end
560
+
561
+ describe ScenarioDefinition, "#yields with after_call block_callback_strategy" do
562
+ it_should_behave_like "RR::ScenarioDefinition#yields"
563
+ it_should_behave_like "RR::ScenarioDefinition with after_call block_callback_strategy"
283
564
 
284
565
  it "sets return value when block passed in" do
285
- @definition.with_any_args.yields {:return_value}
286
- @object.foobar {}.should == :return_value
566
+ @return_value.should == :new_return_value
567
+ @args.should == [:original_return_value]
287
568
  end
288
569
  end
289
570
 
@@ -393,7 +674,7 @@ describe ScenarioDefinition, "#implemented_by_original_method" do
393
674
 
394
675
  it "sets the implementation to the original method" do
395
676
  @definition.implemented_by_original_method.with_any_args
396
- @object.foobar(1, 2).should == [2, 1]
677
+ @object.foobar(1, 2).should == :original_return_value
397
678
  end
398
679
 
399
680
  it "calls method_missing when original_method does not exist" do
@@ -500,4 +781,30 @@ describe ScenarioDefinition, "#expected_arguments" do
500
781
  @definition.expected_arguments.should == []
501
782
  end
502
783
  end
784
+
785
+ describe ScenarioDefinition, "#block_callback_strategy" do
786
+ it_should_behave_like "RR::ScenarioDefinition"
787
+
788
+ it "defaults to :returns" do
789
+ @definition.block_callback_strategy.should == :returns
790
+ end
791
+ end
792
+
793
+ describe ScenarioDefinition, "#returns_block_callback_strategy!" do
794
+ it_should_behave_like "RR::ScenarioDefinition"
795
+
796
+ it "sets the block_callback_strategy to :returns" do
797
+ @definition.returns_block_callback_strategy!
798
+ @definition.block_callback_strategy.should == :returns
799
+ end
800
+ end
801
+
802
+ describe ScenarioDefinition, "#after_call_block_callback_strategy!" do
803
+ it_should_behave_like "RR::ScenarioDefinition"
804
+
805
+ it "sets the block_callback_strategy to :after_call" do
806
+ @definition.after_call_block_callback_strategy!
807
+ @definition.block_callback_strategy.should == :after_call
808
+ end
809
+ end
503
810
  end
@@ -4,10 +4,10 @@ require "spec"
4
4
  class RspecExampleSuite
5
5
  def run
6
6
  options = ::Spec::Runner::OptionParser.new.parse(ARGV.dup, STDERR, STDOUT, false)
7
+ options.configure
7
8
  $behaviour_runner = options.create_behaviour_runner
8
9
 
9
10
  require_specs
10
-
11
11
  puts "Running Rspec Example Suite"
12
12
  $behaviour_runner.run(ARGV, false)
13
13
  end
@@ -7,11 +7,11 @@ module RR
7
7
  attr_accessor :times_called,
8
8
  :argument_expectation,
9
9
  :times_matcher,
10
- :double,
11
10
  :implementation,
12
11
  :after_call_value,
13
12
  :yields_value,
14
13
  :scenario
14
+ attr_reader :block_callback_strategy
15
15
 
16
16
  def initialize(space)
17
17
  @space = space
@@ -20,6 +20,7 @@ module RR
20
20
  @times_matcher = nil
21
21
  @after_call_value = nil
22
22
  @yields_value = nil
23
+ returns_block_callback_strategy!
23
24
  end
24
25
 
25
26
  # Scenario#with sets the expectation that the Scenario will receive
@@ -30,7 +31,7 @@ module RR
30
31
  # mock(subject).method_name.with(1, 2) {:return_value}
31
32
  def with(*args, &returns)
32
33
  @argument_expectation = Expectations::ArgumentEqualityExpectation.new(*args)
33
- returns(&returns) if returns
34
+ install_method_callback returns
34
35
  self
35
36
  end
36
37
 
@@ -42,7 +43,7 @@ module RR
42
43
  # mock(subject).method_name.with_any_args {:return_value}
43
44
  def with_any_args(&returns)
44
45
  @argument_expectation = Expectations::AnyArgumentExpectation.new
45
- returns(&returns) if returns
46
+ install_method_callback returns
46
47
  self
47
48
  end
48
49
 
@@ -54,7 +55,7 @@ module RR
54
55
  # mock(subject).method_name.with_no_args {:return_value}
55
56
  def with_no_args(&returns)
56
57
  @argument_expectation = Expectations::ArgumentEqualityExpectation.new()
57
- returns(&returns) if returns
58
+ install_method_callback returns
58
59
  self
59
60
  end
60
61
 
@@ -77,7 +78,7 @@ module RR
77
78
  # mock(subject).method_name.once {:return_value}
78
79
  def once(&returns)
79
80
  @times_matcher = TimesCalledMatchers::IntegerMatcher.new(1)
80
- returns(&returns) if returns
81
+ install_method_callback returns
81
82
  self
82
83
  end
83
84
 
@@ -89,7 +90,7 @@ module RR
89
90
  # mock(subject).method_name.twice {:return_value}
90
91
  def twice(&returns)
91
92
  @times_matcher = TimesCalledMatchers::IntegerMatcher.new(2)
92
- returns(&returns) if returns
93
+ install_method_callback returns
93
94
  self
94
95
  end
95
96
 
@@ -102,7 +103,7 @@ module RR
102
103
  # mock(subject).method_name.at_least(4) {:return_value}
103
104
  def at_least(number, &returns)
104
105
  @times_matcher = TimesCalledMatchers::AtLeastMatcher.new(number)
105
- returns(&returns) if returns
106
+ install_method_callback returns
106
107
  self
107
108
  end
108
109
 
@@ -115,7 +116,7 @@ module RR
115
116
  # mock(subject).method_name.at_most(4) {:return_value}
116
117
  def at_most(number, &returns)
117
118
  @times_matcher = TimesCalledMatchers::AtMostMatcher.new(number)
118
- returns(&returns) if returns
119
+ install_method_callback returns
119
120
  self
120
121
  end
121
122
 
@@ -128,7 +129,7 @@ module RR
128
129
  # mock(subject).method_name.any_number_of_times
129
130
  def any_number_of_times(&returns)
130
131
  @times_matcher = TimesCalledMatchers::AnyTimesMatcher.new
131
- returns(&returns) if returns
132
+ install_method_callback returns
132
133
  self
133
134
  end
134
135
 
@@ -140,7 +141,7 @@ module RR
140
141
  # mock(subject).method_name.times(4) {:return_value}
141
142
  def times(matcher_value, &returns)
142
143
  @times_matcher = TimesCalledMatchers::TimesCalledMatcher.create(matcher_value)
143
- returns(&returns) if returns
144
+ install_method_callback returns
144
145
  self
145
146
  end
146
147
 
@@ -159,7 +160,7 @@ module RR
159
160
  ) unless @scenario
160
161
  @ordered = true
161
162
  @space.ordered_scenarios << @scenario unless @space.ordered_scenarios.include?(@scenario)
162
- returns(&returns) if returns
163
+ install_method_callback returns
163
164
  self
164
165
  end
165
166
 
@@ -181,7 +182,7 @@ module RR
181
182
  # subject.method_name {|yield_arg1, yield_arg2|}
182
183
  def yields(*args, &returns)
183
184
  @yields_value = args
184
- returns(&returns) if returns
185
+ install_method_callback returns
185
186
  self
186
187
  end
187
188
 
@@ -273,5 +274,23 @@ module RR
273
274
  return [] unless argument_expectation
274
275
  argument_expectation.expected_arguments
275
276
  end
277
+
278
+ def returns_block_callback_strategy! # :nodoc:
279
+ @block_callback_strategy = :returns
280
+ end
281
+
282
+ def after_call_block_callback_strategy! # :nodoc:
283
+ @block_callback_strategy = :after_call
284
+ end
285
+
286
+ protected
287
+ def install_method_callback(block)
288
+ return unless block
289
+ case @block_callback_strategy
290
+ when :returns; returns(&block)
291
+ when :after_call; after_call(&block)
292
+ else raise "Unknown block_callback_strategy: #{@block_callback_strategy.inspect}"
293
+ end
294
+ end
276
295
  end
277
296
  end
@@ -36,6 +36,7 @@ module RR
36
36
  end
37
37
 
38
38
  def probe!
39
+ @definition.after_call_block_callback_strategy!
39
40
  @definition.implemented_by_original_method
40
41
  @definition.after_call(&@handler) if @handler
41
42
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.9
7
- date: 2007-08-14 00:00:00 -07:00
6
+ version: 0.3.10
7
+ date: 2007-08-18 00:00:00 -07:00
8
8
  summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
9
9
  require_paths:
10
10
  - lib
@@ -72,6 +72,7 @@ files:
72
72
  - lib/rr/extensions/instance_methods.rb
73
73
  - examples/environment_fixture_setup.rb
74
74
  - examples/rspec_example_suite.rb
75
+ - examples/core_example_suite.rb
75
76
  - examples/example_suite.rb
76
77
  - examples/example_helper.rb
77
78
  - examples/test_unit_example_suite.rb