Permalink
Browse files

Fixing blocks not being passed to stubs

  • Loading branch information...
1 parent f999770 commit f0c76436b0adacb9a27adbcf7aabd586bfd17197 @aubreyrhodes aubreyrhodes committed Feb 4, 2012
Showing with 19 additions and 2 deletions.
  1. +1 −2 lib/rspec/mocks/message_expectation.rb
  2. +18 −0 spec/rspec/mocks/mock_spec.rb
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 }.

0 comments on commit f0c7643

Please sign in to comment.