Permalink
Browse files

Merge pull request #105 from aubreyrhodes/fix_stub_not_passing_block

Fixing blocks not being passed to stubs
  • Loading branch information...
2 parents f999770 + f0c7643 commit 42b3ef79678a6f526ac0fd325cd5027bd315d2b8 @dchelimsky dchelimsky committed Feb 5, 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
@@ -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)
@@ -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 42b3ef7

Please sign in to comment.