rr 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/README +16 -0
- data/Rakefile +1 -1
- data/examples/rr/scenario_example.rb +53 -1
- data/lib/rr/scenario.rb +35 -3
- metadata +1 -1
data/CHANGES
CHANGED
data/README
CHANGED
@@ -43,3 +43,19 @@ Here is RR compared to other mock frameworks:
|
|
43
43
|
User.should_receive(:find).with('42').and_return(jane) # Rspec
|
44
44
|
User.expects(:find).with('42').returns {jane} # Mocha
|
45
45
|
mock(User).find('42') {jane} # RR
|
46
|
+
|
47
|
+
== Special Thanks To
|
48
|
+
With any development effort, there are countless people who have contributed
|
49
|
+
to making it possible. We all are standing on the shoulders of giants.
|
50
|
+
* Pivotal Labs for sponsoring RR development
|
51
|
+
* Parker Thompson for pairing with me
|
52
|
+
* Felix Morio for pairing with me
|
53
|
+
* David Chelimsky for encouragement to make the RR framework, for developing
|
54
|
+
the Rspec mock framework, and syntax ideas
|
55
|
+
* Gerald Meszaros for his excellent book "xUnit Test Patterns"
|
56
|
+
* Dan North for syntax ideas
|
57
|
+
* Jim Weirich for developing Flexmock, the first Terse ruby mock framework
|
58
|
+
* James Mead for developing Mocha
|
59
|
+
* Aslak Hellesoy for Developing Rspec
|
60
|
+
* Stephen Baker for Developing Rspec
|
61
|
+
* Dave Astels for some BDD inspiration
|
data/Rakefile
CHANGED
@@ -167,13 +167,57 @@ describe Scenario, "#ordered?" do
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
+
describe Scenario, "#yields" do
|
171
|
+
it_should_behave_like "RR::Scenario"
|
172
|
+
|
173
|
+
it "returns self" do
|
174
|
+
@scenario.yields(:baz).should === @scenario
|
175
|
+
end
|
176
|
+
|
177
|
+
it "yields the passed in argument to the call block when there is no returns value set" do
|
178
|
+
@scenario.with_any_args.yields(:baz)
|
179
|
+
passed_in_block_arg = nil
|
180
|
+
@object.foobar {|arg| passed_in_block_arg = arg}.should == nil
|
181
|
+
passed_in_block_arg.should == :baz
|
182
|
+
end
|
183
|
+
|
184
|
+
it "yields the passed in argument to the call block when there is a no returns value set" do
|
185
|
+
@scenario.with_any_args.yields(:baz).returns(:return_value)
|
186
|
+
|
187
|
+
passed_in_block_arg = nil
|
188
|
+
@object.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
|
189
|
+
passed_in_block_arg.should == :baz
|
190
|
+
end
|
191
|
+
|
192
|
+
it "sets return value when block passed in" do
|
193
|
+
@scenario.with_any_args.yields {:return_value}
|
194
|
+
@object.foobar {}.should == :return_value
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
170
198
|
describe Scenario, "#returns" do
|
171
199
|
it_should_behave_like "RR::Scenario"
|
172
200
|
|
173
|
-
it "
|
201
|
+
it "returns self" do
|
174
202
|
@scenario.returns {:baz}.should === @scenario
|
203
|
+
@scenario.returns(:baz).should === @scenario
|
204
|
+
end
|
205
|
+
|
206
|
+
it "sets the value of the method when passed a block" do
|
207
|
+
@scenario.returns {:baz}
|
175
208
|
@scenario.call.should == :baz
|
176
209
|
end
|
210
|
+
|
211
|
+
it "sets the value of the method when passed an argument" do
|
212
|
+
@scenario.returns(:baz)
|
213
|
+
@scenario.call.should == :baz
|
214
|
+
end
|
215
|
+
|
216
|
+
it "raises an error when both argument and block is passed in" do
|
217
|
+
proc do
|
218
|
+
@scenario.returns(:baz) {:another}
|
219
|
+
end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
|
220
|
+
end
|
177
221
|
end
|
178
222
|
|
179
223
|
describe Scenario, "#implemented_by" do
|
@@ -278,6 +322,14 @@ describe Scenario, "#call implemented by a proc" do
|
|
278
322
|
block = @object.foobar(1, 2) {|a, b| [b, a]}
|
279
323
|
block.call(3, 4).should == [4, 3]
|
280
324
|
end
|
325
|
+
|
326
|
+
it "raises ArgumentError when yields was called and no block passed in" do
|
327
|
+
@scenario.with(1, 2).yields(55)
|
328
|
+
|
329
|
+
proc do
|
330
|
+
@object.foobar(1, 2)
|
331
|
+
end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
|
332
|
+
end
|
281
333
|
end
|
282
334
|
|
283
335
|
describe Scenario, "#call implemented by a method" do
|
data/lib/rr/scenario.rb
CHANGED
@@ -11,6 +11,7 @@ module RR
|
|
11
11
|
@argument_expectation = nil
|
12
12
|
@times_called_expectation = nil
|
13
13
|
@times_called = 0
|
14
|
+
@yields = nil
|
14
15
|
end
|
15
16
|
|
16
17
|
# Scenario#with creates an ArgumentEqualityError for the
|
@@ -113,10 +114,35 @@ module RR
|
|
113
114
|
@ordered
|
114
115
|
end
|
115
116
|
|
116
|
-
# Scenario#returns
|
117
|
+
# Scenario#returns accepts an argument value or a block.
|
118
|
+
# It will raise an ArgumentError if both are passed in.
|
119
|
+
#
|
120
|
+
# Passing in a block causes Scenario to return the return value of
|
117
121
|
# the passed in block.
|
118
|
-
|
119
|
-
|
122
|
+
#
|
123
|
+
# Passing in an argument causes Scenario to return the argument.
|
124
|
+
def returns(value=nil, &implementation)
|
125
|
+
raise ArgumentError, "returns cannot accept both an argument and a block" if value && implementation
|
126
|
+
if value
|
127
|
+
implemented_by proc {value}
|
128
|
+
else
|
129
|
+
implemented_by implementation
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Scenario#yields sets the Scenario to invoke a passed in block when
|
134
|
+
# the Scenario is called.
|
135
|
+
# An Expection will be raised if no block is passed in when the
|
136
|
+
# Scenario is called.
|
137
|
+
#
|
138
|
+
# Passing in a block sets the return value.
|
139
|
+
#
|
140
|
+
# mock(subject).method_name.yields(yield_arg1, yield_arg2) {return_value}
|
141
|
+
# subject.method_name {|yield_arg1, yield_arg2|}
|
142
|
+
def yields(*args, &returns)
|
143
|
+
@yields = args
|
144
|
+
returns(&returns) if returns
|
145
|
+
self
|
120
146
|
end
|
121
147
|
|
122
148
|
# Scenario#implemented_by sets the implementation of the Scenario.
|
@@ -141,6 +167,12 @@ module RR
|
|
141
167
|
def call(*args, &block)
|
142
168
|
@times_called_expectation.verify_input if @times_called_expectation
|
143
169
|
@space.verify_ordered_scenario(self) if ordered?
|
170
|
+
if @yields
|
171
|
+
unless block
|
172
|
+
raise ArgumentError, "A Block must be passed into the method call when using yields"
|
173
|
+
end
|
174
|
+
block.call(*@yields)
|
175
|
+
end
|
144
176
|
return nil unless @implementation
|
145
177
|
|
146
178
|
if @implementation.is_a?(Method)
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
6
|
+
version: 0.1.2
|
7
7
|
date: 2007-07-08 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:
|