summaryrefslogtreecommitdiff
path: root/test/psych
diff options
context:
space:
mode:
Diffstat (limited to 'test/psych')
-rw-r--r--test/psych/helper.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/psych/helper.rb b/test/psych/helper.rb
index f9b73cf5b5..11b2216b20 100644
--- a/test/psych/helper.rb
+++ b/test/psych/helper.rb
@@ -83,3 +83,32 @@ module Psych
end
end
end
+
+# backport so that tests will run on 1.9 and 2.0.0
+unless Tempfile.respond_to? :create
+ def Tempfile.create(basename, *rest)
+ tmpfile = nil
+ Dir::Tmpname.create(basename, *rest) do |tmpname, n, opts|
+ mode = File::RDWR|File::CREAT|File::EXCL
+ perm = 0600
+ if opts
+ mode |= opts.delete(:mode) || 0
+ opts[:perm] = perm
+ perm = nil
+ else
+ opts = perm
+ end
+ tmpfile = File.open(tmpname, mode, opts)
+ end
+ if block_given?
+ begin
+ yield tmpfile
+ ensure
+ tmpfile.close if !tmpfile.closed?
+ File.unlink tmpfile
+ end
+ else
+ tmpfile
+ end
+ end
+end