should_receive does not yield block if "and_yield" is attached
Created by: lsegal
This looks like a regression in 2.13.0, it was working before this upgrade.
Example case:
describe Array do
it 'should_receive can take a block' do
block_hit = false
array = []
array.should_receive(:inject) do
block_hit = true
end
array.inject({})
expect(block_hit).to be_true
end
it 'should_receive will not take a block if it also yields' do
block_hit = false
array = []
array.should_receive(:inject) do
block_hit = true
end.and_yield(1)
array.inject({}) {|a| expect(a).to eq(1) }
expect(block_hit).to be_true
end
end
The first example passes, should_receive will properly yield to a block. The second example fails-- when we attach a single and_yield
call, should_receive no longer yields its block.
Output:
$ rspec -v
2.13.0
$ rspec test_spec.rb
.F
Failures:
1) Array should_receive will not take a block if it also yields
Failure/Error: expect(block_hit).to be_true
expected: true value
got: false
# ./test_spec.rb:21:in `block (2 levels) in <top (required)>'
Finished in 0.01277 seconds
2 examples, 1 failure
Failed examples:
rspec ./test_spec.rb:13 # Array should_receive will not take a block if it also yields
I tested this on Ruby 1.9.3 but this actually happens on 1.8.7 all the way through 2.0-- we noticed this on the aws-sdk builds on Travis: https://travis-ci.org/aws/aws-sdk-ruby/builds/5035738