rr 0.3.8 → 0.3.9
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 +3 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/examples/high_level_example.rb +35 -2
- data/examples/rr/rspec/rspec_usage_example.rb +14 -0
- data/examples/rr/scenario_creator_example.rb +16 -1
- data/lib/rr/scenario_creator.rb +1 -0
- metadata +2 -2
data/CHANGES
CHANGED
data/README
CHANGED
@@ -40,7 +40,7 @@ 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
|
-
probe(User).find('5') do |user|
|
43
|
+
mock.probe(User).find('5') do |user|
|
44
44
|
mock.probe(user).projects do |projects|
|
45
45
|
projects[0..3]
|
46
46
|
end
|
data/Rakefile
CHANGED
@@ -62,7 +62,7 @@ describe "RR mock:" do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe "RR probe:" do
|
65
|
+
describe "RR probe or proxy:" do
|
66
66
|
it_should_behave_like "RR"
|
67
67
|
|
68
68
|
it "probes via inline call" do
|
@@ -72,7 +72,7 @@ describe "RR probe:" do
|
|
72
72
|
proc {@obj.to_s}.should raise_error
|
73
73
|
end
|
74
74
|
|
75
|
-
it "allows ordering" do
|
75
|
+
it "probe allows ordering" do
|
76
76
|
def @obj.to_s(arg)
|
77
77
|
"Original to_s with arg #{arg}"
|
78
78
|
end
|
@@ -85,6 +85,19 @@ describe "RR probe:" do
|
|
85
85
|
proc {@obj.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
|
86
86
|
end
|
87
87
|
|
88
|
+
it "proxy allows ordering" do
|
89
|
+
def @obj.to_s(arg)
|
90
|
+
"Original to_s with arg #{arg}"
|
91
|
+
end
|
92
|
+
mock.proxy(@obj).to_s(:foo).ordered
|
93
|
+
mock.proxy(@obj).to_s(:bar).twice.ordered
|
94
|
+
|
95
|
+
@obj.to_s(:foo).should == "Original to_s with arg foo"
|
96
|
+
@obj.to_s(:bar).should == "Original to_s with arg bar"
|
97
|
+
@obj.to_s(:bar).should == "Original to_s with arg bar"
|
98
|
+
proc {@obj.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
|
99
|
+
end
|
100
|
+
|
88
101
|
it "probes via block" do
|
89
102
|
def @obj.foobar_1(*args)
|
90
103
|
:original_value_1
|
@@ -104,6 +117,26 @@ describe "RR probe:" do
|
|
104
117
|
@obj.foobar_2.should == :original_value_2
|
105
118
|
proc {@obj.foobar_2(:blah)}.should raise_error
|
106
119
|
end
|
120
|
+
|
121
|
+
it "proxies via block" do
|
122
|
+
def @obj.foobar_1(*args)
|
123
|
+
:original_value_1
|
124
|
+
end
|
125
|
+
|
126
|
+
def @obj.foobar_2
|
127
|
+
:original_value_2
|
128
|
+
end
|
129
|
+
|
130
|
+
mock.proxy @obj do |c|
|
131
|
+
c.foobar_1(1)
|
132
|
+
c.foobar_2
|
133
|
+
end
|
134
|
+
@obj.foobar_1(1).should == :original_value_1
|
135
|
+
proc {@obj.foobar_1(:blah)}.should raise_error
|
136
|
+
|
137
|
+
@obj.foobar_2.should == :original_value_2
|
138
|
+
proc {@obj.foobar_2(:blah)}.should raise_error
|
139
|
+
end
|
107
140
|
end
|
108
141
|
|
109
142
|
describe "RR stub:" do
|
@@ -49,3 +49,17 @@ describe RR, "#stub and #probe" do
|
|
49
49
|
@subject.foobar.should == :baz
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
describe RR, "#stub and #proxy" do
|
54
|
+
before do
|
55
|
+
@subject = Object.new
|
56
|
+
def @subject.foobar
|
57
|
+
:baz
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "creates a probe Double Scenario" do
|
62
|
+
stub.proxy(@subject).foobar
|
63
|
+
@subject.foobar.should == :baz
|
64
|
+
end
|
65
|
+
end
|
@@ -205,7 +205,7 @@ describe ScenarioCreator, "#do_not_call" do
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
describe ScenarioCreator, "#probe and #stub" do
|
208
|
+
describe ScenarioCreator, "(#probe or #proxy) and #stub" do
|
209
209
|
it_should_behave_like "RR::ScenarioCreator"
|
210
210
|
|
211
211
|
before do
|
@@ -233,6 +233,13 @@ describe ScenarioCreator, "#probe and #stub" do
|
|
233
233
|
@subject.foobar(1, 2).should == :baz
|
234
234
|
end
|
235
235
|
|
236
|
+
it "sets up the RR proxy call chain" do
|
237
|
+
scenario = @creator.stub.proxy(@subject).foobar(1, 2) {:baz}
|
238
|
+
scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
239
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
240
|
+
@subject.foobar(1, 2).should == :baz
|
241
|
+
end
|
242
|
+
|
236
243
|
it "creates a probe Scenario for method when passed a second argument" do
|
237
244
|
scenario = @creator.stub.probe(@subject, :foobar)
|
238
245
|
scenario.with(1, 2) {:baz}
|
@@ -240,6 +247,14 @@ describe ScenarioCreator, "#probe and #stub" do
|
|
240
247
|
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
241
248
|
@subject.foobar(1, 2).should == :baz
|
242
249
|
end
|
250
|
+
|
251
|
+
it "creates a proxy Scenario for method when passed a second argument" do
|
252
|
+
scenario = @creator.stub.proxy(@subject, :foobar)
|
253
|
+
scenario.with(1, 2) {:baz}
|
254
|
+
scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
255
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
256
|
+
@subject.foobar(1, 2).should == :baz
|
257
|
+
end
|
243
258
|
end
|
244
259
|
|
245
260
|
describe ScenarioCreator, "#instance_of" do
|
data/lib/rr/scenario_creator.rb
CHANGED
@@ -167,6 +167,7 @@ module RR
|
|
167
167
|
return self if subject.__id__ === NO_SUBJECT_ARG.__id__
|
168
168
|
RR::Space.scenario_method_proxy(self, subject, method_name, &definition)
|
169
169
|
end
|
170
|
+
alias_method :proxy, :probe
|
170
171
|
|
171
172
|
# Calling instance_of will cause all instances of the passed in Class
|
172
173
|
# to have the Scenario defined.
|
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.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.3.9
|
7
|
+
date: 2007-08-14 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
|