You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I have a test where I want some method foo to do its normal thing the first two times it is called (i.e. no mock interference) but raise an exception the third time it is called. How do I do this with rspec?
The context is something like the following:
# In some class
def bar
foo "first invocation should succeed"
...
foo "second invocation should succeed"
...
foo "third invocation should raise an exception"
end
So how do I tell rspec to "leave foo alone and not override it for the first two invocations" but then "raise an exception for the third invocation using an expectation"?
I know that I can test foo separately, but I am trying to test some complex interactions here and I am unable to force method foo to raise an exception naturally (e.g. if it depends on a third party service) so I need to force it to raise an exception during the third call using an rspec expectation.
But the problem is that setting an rspec expectation overrides the method/stubs it for all three, whereas I just want the last.
Thanks! :-)
The text was updated successfully, but these errors were encountered:
Hi,
Suppose I have a test where I want some method foo to do its normal thing the first two times it is called (i.e. no mock interference) but raise an exception the third time it is called. How do I do this with rspec?
The context is something like the following:
So how do I tell rspec to "leave foo alone and not override it for the first two invocations" but then "raise an exception for the third invocation using an expectation"?
I know that I can test foo separately, but I am trying to test some complex interactions here and I am unable to force method foo to raise an exception naturally (e.g. if it depends on a third party service) so I need to force it to raise an exception during the third call using an rspec expectation.
But the problem is that setting an rspec expectation overrides the method/stubs it for all three, whereas I just want the last.
Thanks! :-)
The text was updated successfully, but these errors were encountered: