diff options
author | Eric Wong <e@80x24.org> | 2016-02-29 08:18:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-02-29 08:22:02 +0000 |
commit | 7ee064f52ee740eeafa49089911f6eca18c67e38 (patch) | |
tree | 6bf2588b7d3b992d38b7056d8a230367cde479eb /test/helper.rb | |
parent | 5fff94f35928feeb9d6bf91087ee7cdbe97ecdb7 (diff) | |
download | yahns-7ee064f52ee740eeafa49089911f6eca18c67e38.tar.gz |
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.
Diffstat (limited to 'test/helper.rb')
-rw-r--r-- | test/helper.rb | 30 |
1 files changed, 16 insertions, 14 deletions
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) |