Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

and_yield not using default block argument when no argument given. #714

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions spec/rspec/mocks/and_yield_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@
verify yielded_arg
end

context "that are optional" do
it "yields the default argument when the argument is not given" do
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
end

it "yields given argument when the argument is given" do
default_arg = Object.new
given_arg = Object.new
obj = Object.new

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

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

it "fails when expectations set on the eval context and yielded arguments are not met" do
configured_eval_context = nil
yielded_arg = Object.new
Expand Down