Skip to content

Instantly share code, notes, and snippets.

@jstultz
Created September 22, 2014 18:04
Show Gist options
  • Select an option

  • Save jstultz/0c0c41e45f82320b3dea to your computer and use it in GitHub Desktop.

Select an option

Save jstultz/0c0c41e45f82320b3dea to your computer and use it in GitHub Desktop.
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