From 7ee064f52ee740eeafa49089911f6eca18c67e38 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 29 Feb 2016 08:18:55 +0000 Subject: test/*: fix mktmpdir usage for 1.9.3 We should not infinite loop, oops :x Also, ensure 'yahns' is in the directory in case tests are SIGKILL-ed and directories are left over. --- test/helper.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'test/helper.rb') diff --git a/test/helper.rb b/test/helper.rb index 8f70ddc..73cde51 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -88,21 +88,23 @@ end require "tempfile" require 'tmpdir' -class Dir - def Dir.mktmpdir - begin - d = "#{Dir.tmpdir}/#$$.#{rand}" - Dir.mkdir(d) - rescue Errno::EEXIST - end while true - return d unless block_given? - begin - yield d - ensure - FileUtils.remove_entry(d) - end + +# Can't rely on mktmpdir until we drop Ruby 1.9.3 support +def yahns_mktmpdir + d = nil + begin + dir = "#{Dir.tmpdir}/yahns.#$$.#{rand}" + Dir.mkdir(dir) + d = dir + rescue Errno::EEXIST + end until d + return d unless block_given? + begin + yield d + ensure + FileUtils.remove_entry(d) end -end unless Dir.respond_to?(:mktmpdir) +end def tmpfile(*args) tmp = Tempfile.new(*args) -- cgit v1.2.3-24-ge0c7