Last active
January 4, 2016 08:48
-
-
Save floehopper/8597397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Thing | |
def execute | |
stubbed_method | |
rescue MyException | |
retry | |
end | |
def stubbed_method | |
# do stuff | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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