From 30bb040ea4718270e269fefdd0440940f2bdfc5d Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Wed, 30 Sep 2020 15:41:14 +0900 Subject: Fix `Leaked tempfile`s http://rubyci.s3.amazonaws.com/debian10/ruby-master/log/20200930T033004Z.diff.html.gz ``` [n/n] JSONCommonInterfaceTest#test_load = s [n/n] JSONCommonInterfaceTest#test_load_file = s +Leaked tempfile: JSONCommonInterfaceTest#test_load_file: #/tmp/20200930-7601-ptnv6i (closed)> [n/n] JSONCommonInterfaceTest#test_load_file! = s +Leaked tempfile: JSONCommonInterfaceTest#test_load_file!: #/tmp/20200930-7601-1la6m9 (closed)> [n/n] JSONCommonInterfaceTest#test_load_file_with_option = s +Leaked tempfile: JSONCommonInterfaceTest#test_load_file_with_option: #/tmp/20200930-7601-blf9hz (closed)> [n/n] JSONCommonInterfaceTest#test_load_file_with_option! = s +Leaked tempfile: JSONCommonInterfaceTest#test_load_file_with_option!: #/tmp/20200930-7601-b5gsdb (closed)> ``` --- test/json/json_common_interface_test.rb | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'test/json') diff --git a/test/json/json_common_interface_test.rb b/test/json/json_common_interface_test.rb index d6fd195706..f87eab0e9c 100644 --- a/test/json/json_common_interface_test.rb +++ b/test/json/json_common_interface_test.rb @@ -157,27 +157,15 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase end end - # Copied and slightly modified from https://github.com/keithrbennett/trick_bag - # (https://github.com/keithrbennett/trick_bag/blob/master/lib/trick_bag/io/temp_files.rb). - # - # For the easy creation and deletion of a temp file populated with text, - # wrapped around the code block you provide. - # - # @param text the text to write to the temporary file - # @param file_prefix optional prefix for the temporary file's name - # @yield filespec of the temporary file def temp_file_containing(text, file_prefix = '') raise "This method must be called with a code block." unless block_given? - filespec = nil begin - Tempfile.open(file_prefix) do |file| + Tempfile.create(file_prefix) do |file| file << text - filespec = file.path + file.close + yield file.path end - yield(filespec) - ensure - File.delete(filespec) if filespec && File.exist?(filespec) end end end -- cgit v1.2.3