fakes 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,3 +1,3 @@
1
1
  module Fakes
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: