I'm trying to test an API wrapper, and it's supposed to retry the external call if the first attempt fails.
In my test, I'm able to stub the call and check that it calls it twice. Which is great :D
stub_request(:get, "http://www.domain.com/")
.to_raise(Exception)
.times(2)
assert_raise(WhitePagesApi::ApiRequestFailed) { MyApiWrapper.new(persistent_http).doCall()) }
assert_requested :get, "http://www.domain.com/",
:times => 2
But the above test only tests that the API call goes out twice. What I need to do is to have the stub raise an exception the first time, then return expected data the second call
Something like:
stub_request(:get, "http://www.domain.com")
.to_raise(Exception)
.then
.to_return(:body => someResponseIPredetermined)
The problem I'm running into is that the stubbing always returns an exception, on both calls.
Any help is much appreciated.