Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teardown test helper leaves configuration behind #2103

Closed
al2o3cr opened this issue Sep 7, 2023 · 0 comments · Fixed by #2116
Closed

Teardown test helper leaves configuration behind #2103

al2o3cr opened this issue Sep 7, 2023 · 0 comments · Fixed by #2116
Assignees
Labels

Comments

@al2o3cr
Copy link

al2o3cr commented Sep 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants