Skip to content

Commit d3ffb95

Browse files
committed
Fix flaky net/http spec
1 parent e3ded02 commit d3ffb95

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,12 @@ def verify_spans(transaction)
371371

372372
it "doesn't mess different requests' data together when making multiple requests with Net::HTTP.start" do
373373
Net::HTTP.start("example.com") do |http|
374-
stub_normal_response(code: "200")
374+
stub_response(http, code: "200")
375375
request = Net::HTTP::Get.new("/path?foo=bar")
376376
response = http.request(request)
377377
expect(response.code).to eq("200")
378378

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

0 commit comments

Comments
 (0)