@@ -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