summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/json_common_interface_test.rb18
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