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

Commit 485a266

Browse files
pirjJonRowe
authored andcommitted
Merge pull request #1585 from rspec/extend-and_invoke-docs
Extend and_invoke docs
1 parent 40cdc47 commit 485a266

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

features/configuring_responses/mixed_responses.feature

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Feature: Mixed responses
44
callables to have different behavior for consecutive calls. The final callable will continue to be
55
called if the message is received additional times.
66

7-
Note: The invoked callable will be invoked with the calls arguments, so it is recommended to
8-
use a `lambda` or similar with the same arity as your method but you can use a `proc` if you
9-
do not care about arity (e.g. when raising).
7+
Note: The invoked callable will be supplied the calls arguments, including any blocks (so `yield`
8+
et al will be supported). It is recommended to use a `lambda` or similar with the same arity
9+
as your method but you can use a `proc` if you do not care about arity(e.g. when raising).
1010

1111
Scenario: Mixed responses
1212
Given a file named "raises_and_then_returns.rb" with:
@@ -23,3 +23,22 @@ Feature: Mixed responses
2323
"""
2424
When I run `rspec raises_and_then_returns.rb`
2525
Then the examples should all pass
26+
27+
Scenario: Block arguments
28+
Given a file named "yields_and_raises.rb" with:
29+
"""ruby
30+
RSpec.describe "when the method is called multiple times" do
31+
it "yields and then later raises" do
32+
dbl = double
33+
allow(dbl).to receive(:foo).and_invoke(
34+
proc { |&block| block.call("foo") },
35+
proc { raise "failure" }
36+
)
37+
38+
dbl.foo { |yielded| expect(yielded).to eq("foo") }
39+
expect { dbl.foo }.to raise_error("failure")
40+
end
41+
end
42+
"""
43+
When I run `rspec yields_and_raises.rb`
44+
Then the examples should all pass

0 commit comments

Comments
 (0)