Open ndbroadbent opened 3 years ago
I'm also experiencing this, if there is any solution that doesnt require disabling webmock it would be great understand if thats possible.
I've found a workaround for this in tests, but it short-circuits streaming responses, so I would not use the workaround in production due to performance concerns.
The solution is to pass the streaming: false
option to the Rack::Proxy
middleware when initializing it.
The problem seems to be that WebMock monkey-patches Net::HTTP#request
and Net::HTTP#start
, including injecting a stubbed socket. Meanwhile, (but only in streaming mode), Rack::Proxy
bypasses Net::HTTP#request
to use lower-level Net::HTTP
methods and obtain a streamable rack response, so the WebMock abstraction is broken and the socket is never set before being used by the underlying Net::HTTP
implementation.
you may choose to disable streaming only in tests, since webmock should only monkey-patch in that environment.
I'm using rack-reverse-proxy, which uses
rack-proxy
.I'm trying to write a test to ensure that
rack-reverse-proxy
is working correctly, but it looks like WebMock / VCR is causing a conflict with thenet_http_hacked
changes in this library.When I call
get
in my test, I see this error:Code:
It looks like
@socket
is nil, maybe because WebMock is also stubbing parts ofNet::HTTP
?Note that this gem does work great in production, but it's really dangerous that I am unable to write any integration tests to ensure that it keeps working properly.
UPDATE: I can get the test to pass if I call
WebMock.disable!
:But it would be great if I could actually mock the requests and save the request/response in VCR.