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
Hello. I am using WebMock for the first time, because I need to stub requests made by RestClient used under the hood.
My test "suite" consists of two or three examples, and I noticed a strange gap reported in coverage. It turned out that examples, when run in isolation, work fine, but when run as a whole context, only the first example works as expected, and the second one silently passes.
I went to extreme and noticed that despite WebMock.reset! the previously set stubs are still effective, and that could be reason for the second example not actually testing anything. It is also prominent in time to run example: singular milliseconds.
Here is current code sample, I was a bit desperate hence the redundant calls:
Note: The download.mycompany.com hostname has to be pass-through, i.e. allow to execute normally.
before(:each)doputs"=== WEBMOCK ENABLE ==="WebMock.enable!WebMock.allow_net_connect!(net_http_connect_on_start: ["download.mycompany.com"])endafter(:each)doputs"=== WEBMOCK RESET ==="WebMock.reset!WebMock.disable_net_connect!WebMock.allow_net_connect!WebMock.disable!endit'should handle multiple redirects with one without host name and absolute path'doWebMock.reset!WebMock::API.stub_request(:get,"http://www.example.com/foo").to_return(status: 302,headers: {'Location'=>'http://www.othersite.com/picture'})WebMock::API.stub_request(:get,"http://www.othersite.com/picture").to_return(status: 302,headers: {'Location'=>'/image.jpg'})WebMock::API.stub_request(:get,"http://www.othersite.com/image.jpg").to_return(status: 200,body: File.new('spec/mountain.jpg'))# Expected resolution of redirectsWebMock::API.stub_request(:get,"http://www.example.com/image.jpg").to_return(status: 404)# Improperly resolved redirecturl='http://www.example.com/foo'show(url,type: :fetch)byebugputs"=== HEADERS 1 === #{response.headers}"expect(response.status).toeq(200)endit'should handle multiple redirects with one without host and relative path'doWebMock.reset!# WebMock::API.stub_request(:get, "http://www.example.com/foo").to_return(status: 302, headers: { 'Location' => 'http://www.othersite.com/folder/picture' })# WebMock::API.stub_request(:get, "http://www.othersite.com/folder/picture").to_return(status: 302, headers: { 'Location' => 'image.jpg' })# WebMock::API.stub_request(:get, "http://www.othersite.com/folder/image.jpg").to_return(status: 200, body: File.new('spec/mountain.jpg')) # Expected resolution of redirects# WebMock::API.stub_request(:get, "http://www.example.com/image.jpg").to_return(status: 404) # Improperly resolved redirecturl='http://www.example.com/foo'show(url,type: :fetch)byebugputs"=== HEADERS 2 === #{response.headers}"expect(response.status).toeq(200)end
Note that despite commenting out the stubbing in second example, the test still passes. I am printing the headers in both cases, and they are exactly the same (with difference on Last-Modified):
Hello. I am using WebMock for the first time, because I need to stub requests made by RestClient used under the hood.
My test "suite" consists of two or three examples, and I noticed a strange gap reported in coverage. It turned out that examples, when run in isolation, work fine, but when run as a whole
context
, only the first example works as expected, and the second one silently passes.I went to extreme and noticed that despite
WebMock.reset!
the previously set stubs are still effective, and that could be reason for the second example not actually testing anything. It is also prominent in time to run example: singular milliseconds.Here is current code sample, I was a bit desperate hence the redundant calls:
Note: The
download.mycompany.com
hostname has to be pass-through, i.e. allow to execute normally.Note that despite commenting out the stubbing in second example, the test still passes. I am printing the headers in both cases, and they are exactly the same (with difference on
Last-Modified
):The text was updated successfully, but these errors were encountered: