Skip to content

Commit 5d9c338

Browse files
authored
Fix flaky net/http spec (#2667)
1 parent e3ded02 commit 5d9c338

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

sentry-ruby/spec/contexts/with_request_mock.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@ def stub_sentry_response
3636
def stub_normal_response(code: "200", &block)
3737
sentry_stub_request(build_fake_response(code), &block)
3838
end
39+
40+
def stub_response(http, code: "200", &block)
41+
fake_response = build_fake_response(code)
42+
43+
allow(http).to receive(:connect)
44+
45+
allow(http).to receive(:transport_request) do |http_obj, request|
46+
block.call(request, http_obj) if block
47+
end.and_return(fake_response)
48+
end
3949
end

sentry-ruby/spec/sentry/net/http_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,15 @@ def verify_spans(transaction)
370370
end
371371

372372
it "doesn't mess different requests' data together when making multiple requests with Net::HTTP.start" do
373+
allow_any_instance_of(Net::HTTP).to receive(:connect)
374+
373375
Net::HTTP.start("example.com") do |http|
374-
stub_normal_response(code: "200")
376+
stub_response(http, code: "200")
375377
request = Net::HTTP::Get.new("/path?foo=bar")
376378
response = http.request(request)
377379
expect(response.code).to eq("200")
378380

379-
stub_normal_response(code: "404")
381+
stub_response(http, code: "404")
380382
request = Net::HTTP::Get.new("/path?foo=bar")
381383
response = http.request(request)
382384
expect(response.code).to eq("404")

0 commit comments

Comments
 (0)