Skip to content

Instantly share code, notes, and snippets.

@floehopper
Last active January 4, 2016 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save floehopper/8597397 to your computer and use it in GitHub Desktop.
Save floehopper/8597397 to your computer and use it in GitHub Desktop.
class Thing
def execute
stubbed_method
rescue MyException
retry
end
def stubbed_method
# do stuff
end
end
describe Thing
it 'does something' do
thing.stub(:stubbed_method, &on_first_invocation_raise(MyException)
thing.execute
expect(thing).to have_received(:stubbed_method).twice
end
private
def on_first_invocation_raise(exception = StandardError)
lambda do
unless @invoked
@invoked = true
raise exception
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment