Created
September 22, 2014 18:04
-
-
Save jstultz/0c0c41e45f82320b3dea to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Foo | |
| def operation | |
| ... | |
| end | |
| end | |
| class FooRetryWrapper | |
| def initialize(foo) | |
| @foo = foo | |
| end | |
| def operation | |
| retries = 3 | |
| begin | |
| foo.operation | |
| rescue => ex | |
| if retries > 0 | |
| retries -= 1 | |
| retry | |
| else | |
| raise | |
| end | |
| end | |
| end | |
| end | |
| # meanwhile, in specs ... this test will pass. | |
| describe FooRetryWrapper | |
| let(:foo) { Foo.new } | |
| let(:foo_retry_wrapper) { FooRetryWrapper.new(foo) } | |
| it "retries the right number of times" do | |
| # This should actually happen 4 times | |
| foo.should_receive(:operation).exactly(2).times.and_raise(SomeError.new) | |
| expect { | |
| thing_retry_wrapper.operation | |
| }.to raise_error # This will catch the RSpec::Mocks::MockExpectationError | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment