Skip to content

Commit

Permalink
sentry-ruby test cleanup (#1593)
Browse files Browse the repository at this point in the history
* Remove unnecessary cause check

* Remove unnecessary test setup

* Don't activate breadcrumb logger in every test

* SDK logger should be disabled in tests
  • Loading branch information
st0012 committed Oct 23, 2021
1 parent f0355dd commit 17836c4
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
28 changes: 14 additions & 14 deletions sentry-ruby/spec/sentry/breadcrumb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@
)
end

let(:problematic_crumb) do
# circular reference
a = []
b = []
a.push(b)
b.push(a)

Sentry::Breadcrumb.new(
category: "baz",
message: "I cause issues",
data: a
)
end

describe "#initialize" do
it "limits the maximum size of message" do
long_message = "a" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES * 2
Expand All @@ -50,6 +36,20 @@
end

describe "#to_hash" do
let(:problematic_crumb) do
# circular reference
a = []
b = []
a.push(b)
b.push(a)

Sentry::Breadcrumb.new(
category: "baz",
message: "I cause issues",
data: a
)
end

it "serializes data correctly" do
result = crumb.to_hash

Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/spec/sentry/client/event_sending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
RSpec.describe Sentry::Client do
let(:configuration) do
Sentry::Configuration.new.tap do |config|
config.logger = Logger.new(nil)
config.dsn = DUMMY_DSN
config.transport.transport_class = Sentry::DummyTransport
end
Expand Down
21 changes: 9 additions & 12 deletions sentry-ruby/spec/sentry/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,19 @@ module ExcTag; end
end
end

# Only check causes when they're supported
if Exception.new.respond_to? :cause
context 'when the exception has a cause' do
let(:exception) { build_exception_with_cause }
context 'when the exception has a cause' do
let(:exception) { build_exception_with_cause }

it 'captures the cause' do
expect(hash[:exception][:values].length).to eq(2)
end
it 'captures the cause' do
expect(hash[:exception][:values].length).to eq(2)
end
end

context 'when the exception has nested causes' do
let(:exception) { build_exception_with_two_causes }
context 'when the exception has nested causes' do
let(:exception) { build_exception_with_two_causes }

it 'captures nested causes' do
expect(hash[:exception][:values].length).to eq(3)
end
it 'captures nested causes' do
expect(hash[:exception][:values].length).to eq(3)
end
end

Expand Down
14 changes: 3 additions & 11 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,9 @@ class MyTestException < RuntimeError; end
subject.inspect_exception_causes_for_exclusion = true
end

if Exception.new.respond_to? :cause
context 'when the language version supports exception causes' do
it 'returns false' do
expect(subject.exception_class_allowed?(incoming_exception)).to eq false
end
end
else
context 'when the language version does not support exception causes' do
it 'returns true' do
expect(subject.exception_class_allowed?(incoming_exception)).to eq true
end
context 'when the language version supports exception causes' do
it 'returns false' do
expect(subject.exception_class_allowed?(incoming_exception)).to eq false
end
end
end
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def inspect
describe "state encapsulation" do
before do
Sentry.configure_scope { |s| s.set_tags(tag_1: "don't change me") }
Sentry.configuration.breadcrumbs_logger = [:sentry_logger]
end

it "only contains the breadcrumbs of the request" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
Sentry.configuration
end
let(:client) { Sentry.get_current_client }
let(:event) { client.event_from_message("foobarbaz") }
let(:data) do
subject.encode(event.to_hash)
subject.encode(client.event_from_message("foobarbaz").to_hash)
end

subject { Sentry::HTTPTransport.new(configuration) }
Expand Down
3 changes: 0 additions & 3 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,10 @@
let(:fake_root) { "/tmp/sentry/" }

before do
allow(File).to receive(:directory?).and_return(false)
allow_any_instance_of(Sentry::Configuration).to receive(:project_root).and_return(fake_root)
ENV["SENTRY_DSN"] = DUMMY_DSN
end

subject { described_class.configuration }

it 'defaults to nil' do
described_class.init
expect(described_class.configuration.release).to eq(nil)
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def build_exception_with_recursive_cause

def perform_basic_setup
Sentry.init do |config|
config.breadcrumbs_logger = [:sentry_logger]
config.logger = Logger.new(nil)
config.dsn = DUMMY_DSN
config.transport.transport_class = Sentry::DummyTransport
# so the events will be sent synchronously for testing
Expand Down

0 comments on commit 17836c4

Please sign in to comment.