Skip to content

Commit de9ba3e

Browse files
committed
Fix after hook to handle mocked Syslog singleton
The after hook that resets @syslog was causing mock expectation errors in config_spec tests that stub Syslog.instance to be called exactly twice. The hook's additional call violated these expectations. Fix by: - Wrapping the reset in begin/rescue to catch MockExpectationError - Only resetting if the instance responds to instance_variable_set (protecting against doubles that don't implement this method) This allows tests that mock the singleton to work correctly while still preventing mock leakage in tests that use the real singleton.
1 parent 225c641 commit de9ba3e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

spec/spec_helper.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,15 @@
207207

208208
rspec_config.after do
209209
# Reset the Syslog sink singleton to prevent mock leakage between tests
210-
Steno::Sink::Syslog.instance.instance_variable_set(:@syslog, nil) if defined?(Steno::Sink::Syslog)
210+
# Only reset if it's the actual singleton instance (not a mock/double)
211+
if defined?(Steno::Sink::Syslog)
212+
begin
213+
instance = Steno::Sink::Syslog.instance
214+
instance.instance_variable_set(:@syslog, nil) if instance.respond_to?(:instance_variable_set)
215+
rescue RSpec::Mocks::MockExpectationError
216+
# Ignore mock expectation errors - the test is managing the mock itself
217+
end
218+
end
211219
end
212220

213221
rspec_config.after(:each, type: :legacy_api) { add_deprecation_warning }

0 commit comments

Comments
 (0)