Skip to content

Commit d064d47

Browse files
committed
Reset codec in syslog singleton to prevent mock leakage
The syslog singleton also stores @codec which can be mocked in tests. Previously we only reset syslog but not codec, causing mock leakage into other tests when the codec double was accessed. Changes: - Reset both syslog and codec in the after hook - Add nil guard for codec in add_record method - Prevents "double leaked into another example" errors
1 parent 5e349d5 commit d064d47

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

lib/steno/sink/syslog.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def open(identity)
3636
def add_record(record)
3737
return if record.log_level == :off
3838
return unless @syslog
39+
return unless @codec
3940

4041
record = truncate_record(record)
4142
msg = @codec.encode_record(record)

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
begin
216216
instance = Steno::Sink::Syslog.instance
217217
instance.instance_variable_set(:@syslog, nil) if instance.respond_to?(:instance_variable_set)
218+
instance.instance_variable_set(:@codec, nil) if instance.respond_to?(:instance_variable_set)
218219
rescue StandardError
219220
# Ignore any errors - the test may be managing the singleton itself
220221
end

0 commit comments

Comments
 (0)