From c94b0e8568fb608ad0890fa9e3bf26997e6a6b50 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Wed, 28 Aug 2013 17:55:50 +0000 Subject: 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 --- test/psych/helper.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 -- cgit v1.2.3