Skip to content

Teardown test helper leaves configuration behind #2103

@al2o3cr

Description

@al2o3cr

Issue Description

Sentry::TestHelper.setup_sentry_test accepts a block that can mutate the configuration to be used, but teardown_sentry_test leaves that configuration in the client.

Reproduction Steps

Added a case to spec/sentry/test_helper_spec.rb that shows this:

  describe "#teardown_sentry_test" do
    let(:custom) { -> (c) { } }
    before do
      setup_sentry_test(&custom)
    end

    it "clears stored events" do
      Sentry.capture_message("foobar")

      expect(sentry_events.count).to eq(1)

      teardown_sentry_test

      expect(sentry_events.count).to eq(0)
    end

    it "clears stored envelopes" do
      event = Sentry.get_current_client.event_from_message("foobar")
      envelope = sentry_transport.envelope_from_event(event)
      sentry_transport.send_envelope(envelope)

      expect(sentry_envelopes.count).to eq(1)

      teardown_sentry_test

      expect(sentry_envelopes.count).to eq(0)
    end

    it "clears the scope" do
      Sentry.set_tags(foo: "bar")

      teardown_sentry_test

      expect(Sentry.get_current_scope.tags).to eq({})
    end

    context "when the configuration is mutated" do
      let(:custom) { -> (c) { c.environment = "quack" } }

      it "rolls back client changes" do
        expect(Sentry.configuration.environment).to eq("quack")

        teardown_sentry_test

        expect(Sentry.configuration.environment).to eq("unspecified")
      end
    end
  end

Expected Behavior

The new spec should pass, because calling teardown_sentry_test should reset the client configuration.

Actual Behavior

Sentry::TestHelper#teardown_sentry_test when the configuration is mutated rolls back client changes
     Failure/Error: expect(Sentry.configuration.environment).to eq("test")
     
       expected: "test"
            got: "quack"
     
       (compared using ==)
     # ./spec/sentry/test_helper_spec.rb:131:in `block (4 levels) in <top (required)>'

Ruby Version

2.6.10

SDK Version

main

Integration and Its Version

No response

Sentry Config

No response

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions