Skip to content

Commit 567ecba

Browse files
committed
Create logger with file name but using tempfile object
1 parent f0fed97 commit 567ecba

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ class CustomLogger
3939

4040
def initialize
4141
@tf = Tempfile.new('customlogger.log')
42-
at_exit do
43-
@tf.close
44-
@tf.unlink
45-
end
42+
@tf.close
43+
at_exit { @tf.unlink }
4644

47-
@logger = Logger.new @tf
45+
@logger = Logger.new @tf.path
4846
@logger.level = Logger::DEBUG
4947
end
5048

5149
def string
5250
@content ||= begin
53-
@tf.close
54-
content = File.read(@tf.path)
55-
content.sub(/\A# Logfile created .+\n/, '')
51+
if File.file?(@tf.path)
52+
content = File.read(@tf.path)
53+
content.sub(/\A# Logfile created .+\n/, '')
54+
end
5655
end
5756
end
5857
end

0 commit comments

Comments
 (0)