Skip to content

Commit

Permalink
DRY up toggling webmock in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Feb 17, 2025
1 parent 3e7aebd commit 6358f7b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 32 deletions.
6 changes: 6 additions & 0 deletions sentry-ruby/spec/contexts/with_request_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def setsockopt(*args); end
allow(TCPSocket).to receive(:open).and_return(FakeSocket.new)
end

around do |example|
WebMock.disable!
example.run
WebMock.enable!
end

def sentry_stub_request(fake_response, &block)
allow_any_instance_of(Net::HTTP).to receive(:connect)
allow_any_instance_of(Net::HTTP).to receive(:transport_request) do |http_obj, request|
Expand Down
6 changes: 0 additions & 6 deletions sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
RSpec.describe :http_logger do
include_context "with request mock"

around do |example|
WebMock.disable!
example.run
WebMock.enable!
end

let(:string_io) { StringIO.new }
let(:logger) do
::Logger.new(string_io)
Expand Down
8 changes: 1 addition & 7 deletions sentry-ruby/spec/sentry/faraday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,7 @@

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

around do |example|
WebMock.disable!
example.run
WebMock.enable!
end

it "skips instrumentation" do
it "skips instrumentation", webmock: false do
transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
RSpec.describe "rate limiting" do
include_context "with request mock"

around do |example|
WebMock.disable!
example.run
WebMock.enable!
end

before do
perform_basic_setup do |config|
config.logger = Logger.new(string_io)
Expand Down
6 changes: 0 additions & 6 deletions sentry-ruby/spec/sentry/transport/http_transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
RSpec.describe Sentry::HTTPTransport do
include_context "with request mock"

around do |example|
WebMock.disable!
example.run
WebMock.enable!
end

let(:configuration) do
Sentry::Configuration.new.tap do |config|
config.dsn = Sentry::TestHelper::DUMMY_DSN
Expand Down
8 changes: 1 addition & 7 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,7 @@
context "with spotlight" do
before { perform_basic_setup { |c| c.spotlight = true } }

around do |example|
WebMock.disable!
example.run
WebMock.enable!
end

it "sends the event to spotlight too" do
it "sends the event to spotlight too", webmock: false do
sentry_stub_request(build_fake_response("200")) do |request, http_obj|
expect(request["Content-Type"]).to eq("application/x-sentry-envelope")
expect(request["Content-Encoding"]).to eq("gzip")
Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
skip("Skipping because one or more guards `#{guards.inspect}` returned false") if skip_examples
end

config.around(:each, webmock: false) do |example|
WebMock.disable!
example.run
WebMock.enable!
end

RSpec::Matchers.define :have_recorded_lost_event do |reason, data_category, num: 1|
match do |transport|
expect(transport.discarded_events[[reason, data_category]]).to eq(num)
Expand Down

0 comments on commit 6358f7b

Please sign in to comment.