Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixing blocks not being passed to stubs #105

Merged
merged 1 commit into from

2 participants

@aubreyrhodes

This looks related to #18 but for stubs instead of expectations:

a = nil
instance = mock
instance.stub(:a_method){|&block| a = block}
b = lambda { }
instance.a_method(&b)

a is nil

@dchelimsky dchelimsky merged commit 42b3ef7 into from
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Simplify some examples.
- #105.
0b4eab2
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Changelog for #105 6743cd7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 4, 2012
  1. @aubreyrhodes
This page is out of date. Refresh to see the latest.
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 }.
Something went wrong with that request. Please try again.