Skip to content

Commit

Permalink
Use Tempfile.create instead of Tempfile.new to avoid fd leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Jul 16, 2021
1 parent 8273d3b commit 25ef7db
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1002,34 +1002,36 @@ def custom_formatter.message_for(spot)
end

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

assert_error_message(NoMethodError, <<~END.gsub("_", "\t")) do
assert_error_message(NoMethodError, <<~END.gsub("_", "\t")) do
undefined method `time' for 1:Integer
_ _1.time {}
_ _ ^^^^^
END

load tmp.path
load tmp.path
end
end
end

def test_no_final_newline
tmp = Tempfile.new(["error_highlight_test", ".rb"])
tmp << "1.time {}"
tmp.close(false)
Tempfile.create(["error_highlight_test", ".rb"], binmode: true) do |tmp|
tmp << "1.time {}"
tmp.close

assert_error_message(NoMethodError, <<~END) do
assert_error_message(NoMethodError, <<~END) do
undefined method `time' for 1:Integer
1.time {}
^^^^^
END

load tmp.path
load tmp.path
end
end
end
end

0 comments on commit 25ef7db

Please sign in to comment.