This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
features/configuring_responses Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ Feature: Mixed responses
88 use a `lambda` or similar with the same arity as your method but you can use a `proc` if you
99 do not care about arity (e.g. when raising).
1010
11+ Note: You can also use `and_invoke` to yield. In this case, use a `proc` with a `&block`
12+ parameter.
13+
1114 Scenario : Mixed responses
1215 Given a file named "raises_and_then_returns.rb" with:
1316 """ruby
@@ -23,3 +26,22 @@ Feature: Mixed responses
2326 """
2427 When I run `rspec raises_and_then_returns.rb`
2528 Then the examples should all pass
29+
30+ Scenario : Yielding
31+ Given a file named "yields_and_raises.rb" with:
32+ """ruby
33+ RSpec.describe "when the method is called multiple times" do
34+ it "yields and then later raises" do
35+ dbl = double
36+ allow(dbl).to receive(:foo).and_invoke(
37+ proc { |&block| block.call("foo") },
38+ proc { raise "failure" }
39+ )
40+
41+ dbl.foo { |yielded| expect(yielded).to eq("foo") }
42+ expect { dbl.foo }.to raise_error("failure")
43+ end
44+ end
45+ """
46+ When I run `rspec yields_and_raises.rb`
47+ Then the examples should all pass
You can’t perform that action at this time.
0 commit comments