Skip to content

Commit 8b353a1

Browse files
committed
Fix leaked tempfiles
1 parent 8273d3b commit 8b353a1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

test/test_error_highlight.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,34 +1002,36 @@ def custom_formatter.message_for(spot)
10021002
end
10031003

10041004
def test_hard_tabs
1005-
tmp = Tempfile.new(["error_highlight_test", ".rb"], binmode: true)
1006-
tmp << "\t \t1.time {}\n"
1007-
tmp.close(false)
1005+
Tempfile.create(["error_highlight_test", ".rb"], binmode: true) do |tmp|
1006+
tmp << "\t \t1.time {}\n"
1007+
tmp.close
10081008

1009-
assert_error_message(NoMethodError, <<~END.gsub("_", "\t")) do
1009+
assert_error_message(NoMethodError, <<~END.gsub("_", "\t")) do
10101010
undefined method `time' for 1:Integer
10111011
10121012
_ _1.time {}
10131013
_ _ ^^^^^
10141014
END
10151015

1016-
load tmp.path
1016+
load tmp.path
1017+
end
10171018
end
10181019
end
10191020

10201021
def test_no_final_newline
1021-
tmp = Tempfile.new(["error_highlight_test", ".rb"])
1022-
tmp << "1.time {}"
1023-
tmp.close(false)
1022+
Tempfile.create(["error_highlight_test", ".rb"]) do |tmp|
1023+
tmp << "1.time {}"
1024+
tmp.close
10241025

1025-
assert_error_message(NoMethodError, <<~END) do
1026+
assert_error_message(NoMethodError, <<~END) do
10261027
undefined method `time' for 1:Integer
10271028
10281029
1.time {}
10291030
^^^^^
10301031
END
10311032

1032-
load tmp.path
1033+
load tmp.path
1034+
end
10331035
end
10341036
end
10351037
end

0 commit comments

Comments
 (0)