summaryrefslogtreecommitdiff
path: root/test/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-28 17:55:50 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-28 17:55:50 +0000
commitc94b0e8568fb608ad0890fa9e3bf26997e6a6b50 (patch)
treece2a85c8ba858e15a7194b32033330e7ebfbb5b1 /test/psych
parent621c6dda368134dd7e52d8a1ec24b81fa05b6859 (diff)
backport Tempfile.create so psych tests will run outside ruby trunk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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