Possibly a strange request here but...
Would it be possible to mock an HTTP Timeout? I am testing error handling and the ability to mock a request to timeout would be very useful.
Hi Jeffrey,
I was thinking about this feature. WebMock could have something like stub_request(:get, "www.google.com").to_timeout
Currently you can achieve this functionality by using .to_raise(e) where e is a library specific timeout exception.
The whole point of webmock is to be http client library independent so to_timeout should work with every library.
The problem is that different libraries return different errors, ie Net::HTTP return Ruby Timeout::Error while HTTPClient raises HTTPClient::TimeoutError.
This behaviour can be replicated in WebMock but the error handling code will have to be different any time you change the library.
Ooo I didn't know about to_raise. While a generic to_timeout would of course be nicer I am quite happy with to_raise for my purposes.
Added in master.
You can do the following now:
stub_request(:any, 'www.example.net').to_timeout
RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
It will always raise http client specific timeout exception.
Groovy, thanks very much!
Most helpful comment
Added in master.
You can do the following now:
It will always raise http client specific timeout exception.