diff options
author | Kazuhiro NISHIYAMA <zn@mbf.nifty.com> | 2020-09-30 15:41:14 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-11-12 21:45:06 +0900 |
commit | cd2e02c2115a5c0e25eaf59db53333fa7a68fbf9 (patch) | |
tree | 0e76deef96591d28916af0395daa45e5f139882c /tests | |
parent | 934e43323856431ceba4a6078a87a03140baa7e2 (diff) | |
download | json-cd2e02c2115a5c0e25eaf59db53333fa7a68fbf9.tar.gz |
Fix `Leaked tempfile`s
http://rubyci.s3.amazonaws.com/debian10/ruby-master/log/20200930T033004Z.diff.html.gz
```
[n/n] JSONCommonInterfaceTest#test_load = <elapsed> s
[n/n] JSONCommonInterfaceTest#test_load_file = <elapsed> s
+Leaked tempfile: JSONCommonInterfaceTest#test_load_file: #<Tempfile:<build-dir>/tmp/20200930-7601-ptnv6i (closed)>
[n/n] JSONCommonInterfaceTest#test_load_file! = <elapsed> s
+Leaked tempfile: JSONCommonInterfaceTest#test_load_file!: #<Tempfile:<build-dir>/tmp/20200930-7601-1la6m9 (closed)>
[n/n] JSONCommonInterfaceTest#test_load_file_with_option = <elapsed> s
+Leaked tempfile: JSONCommonInterfaceTest#test_load_file_with_option: #<Tempfile:<build-dir>/tmp/20200930-7601-blf9hz (closed)>
[n/n] JSONCommonInterfaceTest#test_load_file_with_option! = <elapsed> s
+Leaked tempfile: JSONCommonInterfaceTest#test_load_file_with_option!: #<Tempfile:<build-dir>/tmp/20200930-7601-b5gsdb (closed)>
```
Diffstat (limited to 'tests')
-rw-r--r-- | tests/json_common_interface_test.rb | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/tests/json_common_interface_test.rb b/tests/json_common_interface_test.rb index faa908e..68ad756 100644 --- a/tests/json_common_interface_test.rb +++ b/tests/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 |