Skip to content

Commit ceaba54

Browse files
solnicclaude
andauthored
test(rails): stop the uninitialized-Sentry stub leaking into cleanup
The example stubs Sentry.initialized? to false, and RSpec tears mocks down after the suite's after hooks run. The sentry-rails hook only clears captured events and detaches the structured logging subscribers when Sentry reports itself initialized, so the stub made it skip both. The subscribers stayed attached and later examples inherited log events they never emitted, failing whenever the order put them after this one. Scoping the stub to the call under test lets the hook see the real state. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent e96ad96 commit ceaba54

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

sentry-rails/spec/sentry/rails/capture_context_spec.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ def call(env)
5656
end
5757

5858
it "is a no-op when Sentry is not initialized" do
59-
allow(Sentry).to receive(:initialized?).and_return(false)
60-
6159
called = false
6260
app = lambda do |env|
6361
called = true
6462
[200, {}, ["ok"]]
6563
end
6664

6765
env = Rack::MockRequest.env_for("/test")
68-
described_class.new(app).call(env)
66+
67+
# the stub has to be gone before the suite's after hooks run: they skip
68+
# clearing events and detaching the log subscribers unless Sentry reports
69+
# itself initialized, which would leak log events into later examples
70+
RSpec::Mocks.with_temporary_scope do
71+
allow(Sentry).to receive(:initialized?).and_return(false)
72+
described_class.new(app).call(env)
73+
end
6974

7075
expect(called).to eq(true)
7176
expect(env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY]).to be_nil

0 commit comments

Comments
 (0)