fakes 1.0.0 → 1.0.1
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/lib/core/fake.rb +4 -0
- data/lib/core/version.rb +1 -1
- data/spec/specs/fake_spec.rb +61 -0
- metadata +1 -1
data/lib/core/fake.rb
CHANGED
@@ -8,6 +8,10 @@ module Fakes
|
|
8
8
|
return @method_invocations.has_key?(name.to_sym) ? @method_invocations[name.to_sym].invoke(args) : handle_unexpected_method_invocation(name,args,block)
|
9
9
|
end
|
10
10
|
|
11
|
+
def send(name,*args,&block)
|
12
|
+
return method_missing(name,*args,&block)
|
13
|
+
end
|
14
|
+
|
11
15
|
def handle_unexpected_method_invocation(name,args,block)
|
12
16
|
method = stub(name.to_sym)
|
13
17
|
method.ignore_arg
|
data/lib/core/version.rb
CHANGED
data/spec/specs/fake_spec.rb
CHANGED
@@ -134,6 +134,67 @@ module Fakes
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
context "when send is triggered" do
|
138
|
+
class FakeInvocation
|
139
|
+
attr_accessor :invoke_was_called,:args,:return_value,:ignores_args
|
140
|
+
|
141
|
+
def initialize(return_value)
|
142
|
+
@return_value = return_value
|
143
|
+
end
|
144
|
+
|
145
|
+
def invoke(args)
|
146
|
+
@args = args
|
147
|
+
return @return_value
|
148
|
+
end
|
149
|
+
|
150
|
+
def ignore_arg
|
151
|
+
@ignores_args = true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
let(:invocations){Hash.new}
|
155
|
+
let(:sut){Fake.new(invocations)}
|
156
|
+
let(:symbol){:hello}
|
157
|
+
let(:invocation){FakeInvocation.new(Object.new)}
|
158
|
+
let(:args){"world"}
|
159
|
+
context "and the method is for an invocation that was prepared" do
|
160
|
+
before (:each) do
|
161
|
+
invocations[symbol] = invocation
|
162
|
+
end
|
163
|
+
before (:each) do
|
164
|
+
@result = sut.send(:hello,args)
|
165
|
+
end
|
166
|
+
it "should trigger the invocation with the arguments" do
|
167
|
+
invocation.args.should == [args]
|
168
|
+
end
|
169
|
+
it "should return the result of triggering the invocation" do
|
170
|
+
@result.should == invocation.return_value
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context "and the method is for an invocation that was not prepared" do
|
174
|
+
before (:each) do
|
175
|
+
MethodStub.stub(:new).and_return(invocation)
|
176
|
+
end
|
177
|
+
before (:each) do
|
178
|
+
@result = sut.send(:hello,args)
|
179
|
+
end
|
180
|
+
it "should add a new invocation which ignores arguments to the list of all invocations" do
|
181
|
+
invocations.has_key?(:hello).should be_true
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should configure the new invocation to ignore all arguments" do
|
185
|
+
invocation.ignores_args.should be_true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should invoke the invocation with the arguments" do
|
189
|
+
invocation.args.should == [args]
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should return the result of triggering the new invocation" do
|
193
|
+
@result.should == invocation.return_value
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
137
198
|
context "scenarios" do
|
138
199
|
context "setting up return values using argument matchers" do
|
139
200
|
it "should be able to intercept on methods using the matches factory" do
|