You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require"httpclient"require"webmock"require"webmock/rspec/matchers"RSpec.describe"webmock issue"dobefore(:all)doWebMock.enable!WebMock.disable_net_connect!
$client =HTTPClient.new(base_url: "https://my.cool.service.com")endit"caches nil responses for missing stubs"doexpect{
$client.get('info')}.toraise_error(WebMock::NetConnectNotAllowedError)endit"fails afterwards even if correct stub is present"dostub=WebMock.stub_request(:get,"https://my.cool.service.com/info")
$client.get('info')expect(stub).tohave_been_requestedendend
The second example fails iff performed in order. It runs fine when ran alone.
This example is the result of hours of debugging where I finally found that HTTPClientAdapter#webmock_responses caches responses.
Because we have a test where the client is hold by some kind of adapter which is kind of global (simulated by the $client in the example above), this affects follow.-up tests.
We can work around this problem by monkey-patching HTTPClientAdapter#webmock_responses to
Given the following RSpec test:
The second example fails iff performed in order. It runs fine when ran alone.
This example is the result of hours of debugging where I finally found that
HTTPClientAdapter#webmock_responses
caches responses.Because we have a test where the client is hold by some kind of adapter which is kind of global (simulated by the
$client
in the example above), this affects follow.-up tests.We can work around this problem by monkey-patching
HTTPClientAdapter#webmock_responses
tobut probably, the memoization is there fore a reason, isn’t it?
The text was updated successfully, but these errors were encountered: