Skip to content

Commit cdbb73f

Browse files
committed
DRY up toggling webmock in specs
1 parent 8257b49 commit cdbb73f

File tree

7 files changed

+14
-32
lines changed

7 files changed

+14
-32
lines changed

Diff for: sentry-ruby/spec/contexts/with_request_mock.rb

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def setsockopt(*args); end
1212
allow(TCPSocket).to receive(:open).and_return(FakeSocket.new)
1313
end
1414

15+
around do |example|
16+
WebMock.disable!
17+
example.run
18+
WebMock.enable!
19+
end
20+
1521
def sentry_stub_request(fake_response, &block)
1622
allow_any_instance_of(Net::HTTP).to receive(:connect)
1723
allow_any_instance_of(Net::HTTP).to receive(:transport_request) do |http_obj, request|

Diff for: sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
RSpec.describe :http_logger do
77
include_context "with request mock"
88

9-
around do |example|
10-
WebMock.disable!
11-
example.run
12-
WebMock.enable!
13-
end
14-
159
let(:string_io) { StringIO.new }
1610
let(:logger) do
1711
::Logger.new(string_io)

Diff for: sentry-ruby/spec/sentry/faraday_spec.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,7 @@
271271

272272
let(:url) { "http://example.com" }
273273

274-
around do |example|
275-
WebMock.disable!
276-
example.run
277-
WebMock.enable!
278-
end
279-
280-
it "skips instrumentation" do
274+
it "skips instrumentation", webmock: false do
281275
transaction = Sentry.start_transaction
282276
Sentry.get_current_scope.set_span(transaction)
283277

Diff for: sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
RSpec.describe "rate limiting" do
77
include_context "with request mock"
88

9-
around do |example|
10-
WebMock.disable!
11-
example.run
12-
WebMock.enable!
13-
end
14-
159
before do
1610
perform_basic_setup do |config|
1711
config.logger = Logger.new(string_io)

Diff for: sentry-ruby/spec/sentry/transport/http_transport_spec.rb

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
RSpec.describe Sentry::HTTPTransport do
77
include_context "with request mock"
88

9-
around do |example|
10-
WebMock.disable!
11-
example.run
12-
WebMock.enable!
13-
end
14-
159
let(:configuration) do
1610
Sentry::Configuration.new.tap do |config|
1711
config.dsn = Sentry::TestHelper::DUMMY_DSN

Diff for: sentry-ruby/spec/sentry_spec.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,7 @@
183183
context "with spotlight" do
184184
before { perform_basic_setup { |c| c.spotlight = true } }
185185

186-
around do |example|
187-
WebMock.disable!
188-
example.run
189-
WebMock.enable!
190-
end
191-
192-
it "sends the event to spotlight too" do
186+
it "sends the event to spotlight too", webmock: false do
193187
sentry_stub_request(build_fake_response("200")) do |request, http_obj|
194188
expect(request["Content-Type"]).to eq("application/x-sentry-envelope")
195189
expect(request["Content-Encoding"]).to eq("gzip")

Diff for: sentry-ruby/spec/spec_helper.rb

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
skip("Skipping because one or more guards `#{guards.inspect}` returned false") if skip_examples
7171
end
7272

73+
config.around(:each, webmock: false) do |example|
74+
WebMock.disable!
75+
example.run
76+
WebMock.enable!
77+
end
78+
7379
RSpec::Matchers.define :have_recorded_lost_event do |reason, data_category, num: 1|
7480
match do |transport|
7581
expect(transport.discarded_events[[reason, data_category]]).to eq(num)

0 commit comments

Comments
 (0)