dbl.stub(:raise_then_return) do
@counter = @counter.to_i.succ
raise RuntimeError if @counter < 2
return "foo"
endWhat is the preferred way to express my stub? I need a method that raises on first call and then returns something on the second call.
Many thanks for considering my request.With the newer, non-monkey patching syntax, you would do:
allow(dbl).to receive(:raise_then_return) do
@counter = @counter.to_i.succ
raise RuntimeError if @counter < 2
"foo"
end
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/eb57df04-8ab3-4503-8c4e-89ab5c468e4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.