ruby-changes:30640
From: tenderlove <ko1@a...>
Date: Thu, 29 Aug 2013 02:55:53 +0900 (JST)
Subject: [ruby-changes:30640] tenderlove:r42719 (trunk): backport Tempfile.create so psych tests will run outside ruby trunk
tenderlove 2013-08-29 02:55:50 +0900 (Thu, 29 Aug 2013) New Revision: 42719 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42719 Log: backport Tempfile.create so psych tests will run outside ruby trunk Modified files: trunk/test/psych/helper.rb Index: test/psych/helper.rb =================================================================== --- test/psych/helper.rb (revision 42718) +++ test/psych/helper.rb (revision 42719) @@ -83,3 +83,32 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/helper.rb#L83 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/