Is this chain possible? to_raise(Exception).then.to_return(blah)

8 views
Skip to first unread message

j...@invoca.com

unread,
May 13, 2015, 2:17:07 PM5/13/15
to webmoc...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages