Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing blocks not being passed to stubs

  • Loading branch information...
commit f0c76436b0adacb9a27adbcf7aabd586bfd17197 1 parent f999770
@aubreyrhodes aubreyrhodes authored
View
3  lib/rspec/mocks/message_expectation.rb
@@ -457,11 +457,10 @@ def invoke_consecutive_return_block(*args, &block)
end
def invoke_return_block(*args, &block)
- args << block unless block.nil?
# Ruby 1.9 - when we set @return_block to return values
# regardless of arguments, any arguments will result in
# a "wrong number of arguments" error
- @return_block.arity == 0 ? @return_block.call : @return_block.call(*args)
+ @return_block.arity == 0 ? @return_block.call(&block) : @return_block.call(*args, &block)
end
def clone_args_to_yield(*args)
View
18 spec/rspec/mocks/mock_spec.rb
@@ -185,6 +185,24 @@ def @mock.method_with_default_argument(arg={}); end
@mock.rspec_verify
end
+ it "passes block to stub block with an argument", :ruby => '> 1.8.6' do
+ a = nil
+ eval("@mock.stub(:something){|something_else, &block| a = block}")
+ b = lambda { }
+ @mock.something(nil, &b)
+ a.should eq b
+ @mock.rspec_verify
+ end
+
+ it "passes block to stub block without an argurment", :ruby => '>1.8.6' do
+ a = nil
+ eval("@mock.stub(:something){|&block| a = block}")
+ b = lambda { }
+ @mock.something(&b)
+ a.should eq b
+ @mock.rspec_verify
+ end
+
it "fails right away when method defined as never is received" do
@mock.should_receive(:not_expected).never
expect { @mock.not_expected }.
Please sign in to comment.
Something went wrong with that request. Please try again.