Skip to content

`and_yield` not using default block argument when no argument given.

gitlab-qa-bot requested to merge github/fork/tom025/master into master

Created by: tom025

Using ruby 2.1.2

default_arg = Object.new
obj = Object.new

allow(obj).to receive(:a_message).and_yield
expect(default_arg).to receive(:bar)

obj.a_message do |receiver=default_arg|
  receiver.bar
end

The above code fails with:

 Failure/Error: obj.a_message do |receiver=default_arg|
        #<Object:0x007fe3ac1ce408> yielded || to block with arity of 1

The block has a arity of 0 or 1 not 1. So I would expect that when no argument is given to and_yield it would use the default block argument.

I have a supplied a test that exposes this but I'm not sure how to fix this.

Merge request reports