Repository: rubyzip/rubyzip (ruby)

Issue:
Seemingly random test failures in Travis
I can't reproduce this locally, all tests pass all the time, but on Travis we are seeing different jobs within builds fail each time:
- https://travis-ci.org/rubyzip/rubyzip/builds/28115164 (ruby-head and jruby oracle fail)
- https://travis-ci.org/rubyzip/rubyzip/builds/28153919 (2.0.0, 2.1 and rbx-2 fail)
- https://travis-ci.org/rubyzip/rubyzip/builds/27791940 (no fails apart from broken rbx)
- https://travis-ci.org/rubyzip/rubyzip/builds/28113399 (both jrubys fail)

The common factor with the failures seems to be testing for existing files within a zip and/or unpacking a zip on top of files that already exist. Exceptions that are expected for these tests are not being raised.

Given that it appears to be random, and that I can't replicate it locally, I wonder if it's a race condition in the tests exposed by virtualized disks on the test machines. I might be way off with this though.

Any ideas?



Discussion:
I've had another look at this and noticed that Travis was installing later versions of some gems than I had installed on my machine. So I did a `bundle update`:

```
$ bundle update
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.3.2
Using coderay 1.1.0
Using multi_json 1.10.1
Using mime-types 2.3
Installing netrc 0.7.7
Installing rest-client 1.7.2 (was 1.6.7)
Using docile 1.1.5
Using simplecov-html 0.8.0
Using simplecov 0.8.2
Using tins 1.3.0
Using term-ansicolor 1.3.0
Using thor 0.19.1
Using coveralls 0.7.0
Using method_source 0.8.2
Installing minitest 5.4.0 (was 4.7.5)
Using slop 3.5.0
Using pry 0.10.0
Using rubyzip 1.1.6 from source at .
Using bundler 1.6.2
Your bundle is updated!
```

So three updates happened. Minitest and rest-client were both updated to much newer versions and netrc is a newly installed gem.

Now I see the failures locally too, as described in my original post. Any ideas why this might be given which gems changed? It makes no sense to me at all.


Patch:
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -1,20 +1,5 @@
 .idea
 *.gem
-test/5entry_copy.zip
-test/cdirtest.bin
-test/cdir64test.bin
-test/huge.zip
-test/centralEntryHeader.bin
-test/data/generated/
-test/deflatertest.bin
-test/compressiontest_*.bin
-test/dummy.txt
-test/localEntryHeader.bin
-test/okToDeleteMoved.txt
-test/output.zip
-test/test_putOnClosedStream.zip
-test/zipWithDirs_copy.zip
-test/coverage
 .bundle
 Gemfile.lock
 +samples/*.zip
diff --git a/Gemfile b/Gemfile
--- a/Gemfile
+++ b/Gemfile
@@ -1,7 +1,3 @@
 source 'https://rubygems.org'
 
 gemspec
-gem 'rake'
-gem 'coveralls', :require => false
-gem 'pry'
-gem 'minitest'
diff --git a/rubyzip.gemspec b/rubyzip.gemspec
--- a/rubyzip.gemspec
+++ b/rubyzip.gemspec
@@ -16,4 +16,8 @@ spec = Gem::Specification.new do |s|
   s.require_paths         = ['lib']
   s.license               = 'BSD 2-Clause'
   s.required_ruby_version = '>= 1.9.2'
+  s.add_development_dependency 'rake', '~> 10.3'
+  s.add_development_dependency 'pry', '~> 0.10'
+  s.add_development_dependency 'minitest', '~> 5.2.0'
+  s.add_development_dependency 'coveralls', '~> 0.7'
 end


Test patch:
diff --git a/test/basic_zip_file_test.rb b/test/basic_zip_file_test.rb
--- a/test/basic_zip_file_test.rb
+++ b/test/basic_zip_file_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class BasicZipFileTest < MiniTest::Unit::TestCase
+class BasicZipFileTest < MiniTest::Test
   include AssertEntry
 
   def setup
diff --git a/test/central_directory_entry_test.rb b/test/central_directory_entry_test.rb
--- a/test/central_directory_entry_test.rb
+++ b/test/central_directory_entry_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class ZipCentralDirectoryEntryTest < MiniTest::Unit::TestCase
+class ZipCentralDirectoryEntryTest < MiniTest::Test
 
   def test_read_from_stream
     File.open("test/data/testDirectory.bin", "rb") {
diff --git a/test/central_directory_test.rb b/test/central_directory_test.rb
--- a/test/central_directory_test.rb
+++ b/test/central_directory_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class ZipCentralDirectoryTest < MiniTest::Unit::TestCase
+class ZipCentralDirectoryTest < MiniTest::Test
 
   def test_read_from_stream
     ::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") {
diff --git a/test/deflater_test.rb b/test/deflater_test.rb
--- a/test/deflater_test.rb
+++ b/test/deflater_test.rb
@@ -1,12 +1,17 @@
 require 'test_helper'
 
-class DeflaterTest < MiniTest::Unit::TestCase
+class DeflaterTest < MiniTest::Test
   include CrcTest
 
+  DEFLATER_TEST_FILE = 'test/data/generated/deflatertest.bin'
+  BEST_COMP_FILE = 'test/data/generated/compressiontest_best_compression.bin'
+  DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
+  NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin'
+
   def test_outputOperator
     txt = load_file("test/data/file2.txt")
-    deflate(txt, "deflatertest.bin")
-    inflatedTxt = inflate("deflatertest.bin")
+    deflate(txt, DEFLATER_TEST_FILE)
+    inflatedTxt = inflate(DEFLATER_TEST_FILE)
     assert_equal(txt, inflatedTxt)
   end
 
@@ -14,15 +19,15 @@ def test_default_compression
     txt = load_file("test/data/file2.txt")
 
     Zip.default_compression = ::Zlib::BEST_COMPRESSION
-    deflate(txt, "compressiontest_best_compression.bin")
+    deflate(txt, BEST_COMP_FILE)
     Zip.default_compression = ::Zlib::DEFAULT_COMPRESSION
-    deflate(txt, "compressiontest_default_compression.bin")
+    deflate(txt, DEFAULT_COMP_FILE)
     Zip.default_compression = ::Zlib::NO_COMPRESSION
-    deflate(txt, "compressiontest_no_compression.bin")
+    deflate(txt, NO_COMP_FILE)
 
-    best    = File.size("compressiontest_best_compression.bin")
-    default = File.size("compressiontest_default_compression.bin")
-    no      = File.size("compressiontest_no_compression.bin")
+    best    = File.size(BEST_COMP_FILE)
+    default = File.size(DEFAULT_COMP_FILE)
+    no      = File.size(NO_COMP_FILE)
 
     assert(best < default)
     assert(best < no)
diff --git a/test/entry_set_test.rb b/test/entry_set_test.rb
--- a/test/entry_set_test.rb
+++ b/test/entry_set_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class ZipEntrySetTest < MiniTest::Unit::TestCase
+class ZipEntrySetTest < MiniTest::Test
   ZIP_ENTRIES = [
       ::Zip::Entry.new("zipfile.zip", "name1", "comment1"),
       ::Zip::Entry.new("zipfile.zip", "name3", "comment1"),
diff --git a/test/entry_test.rb b/test/entry_test.rb
--- a/test/entry_test.rb
+++ b/test/entry_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class ZipEntryTest < MiniTest::Unit::TestCase
+class ZipEntryTest < MiniTest::Test
   TEST_ZIPFILE = "someZipFile.zip"
   TEST_COMMENT = "a comment"
   TEST_COMPRESSED_SIZE = 1234
@@ -131,7 +131,7 @@ def test_entry_name_cannot_start_with_slash
   end
 
   def test_store_file_without_compression
-    File.delete('/tmp/no_compress.zip') if File.exists?('/tmp/no_compress.zip')
+    File.delete('/tmp/no_compress.zip') if File.exist?('/tmp/no_compress.zip')
     files = Dir[File.join('test/data/globTest', '**', '**')]
 
     Zip.setup do |z|
diff --git a/test/errors_test.rb b/test/errors_test.rb
--- a/test/errors_test.rb
+++ b/test/errors_test.rb
@@ -1,7 +1,7 @@
 # encoding: utf-8
 require 'test_helper'
 
-class ErrorsTest < MiniTest::Unit::TestCase
+class ErrorsTest < MiniTest::Test
 
   def test_rescue_legacy_zip_error
     raise ::Zip::Error
diff --git a/test/extra_field_test.rb b/test/extra_field_test.rb
--- a/test/extra_field_test.rb
+++ b/test/extra_field_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class ZipExtraFieldTest < MiniTest::Unit::TestCase
+class ZipExtraFieldTest < MiniTest::Test
   def test_new
     extra_pure = ::Zip::ExtraField.new("")
     extra_withstr = ::Zip::ExtraField.new("foo")
diff --git a/test/file_extract_directory_test.rb b/test/file_extract_directory_test.rb
--- a/test/file_extract_directory_test.rb
+++ b/test/file_extract_directory_test.rb
@@ -1,8 +1,9 @@
 require 'test_helper'
 
-class ZipFileExtractDirectoryTest < MiniTest::Unit::TestCase
+class ZipFileExtractDirectoryTest < MiniTest::Test
   include CommonZipFileFixture
-  TEST_OUT_NAME = "emptyOutDir"
+
+  TEST_OUT_NAME = "test/data/generated/emptyOutDir"
 
   def open_zip(&aProc)
     assert(aProc != nil)
diff --git a/test/file_extract_test.rb b/test/file_extract_test.rb
--- a/test/file_extract_test.rb
+++ b/test/file_extract_test.rb
@@ -1,8 +1,8 @@
 require 'test_helper'
 
-class ZipFileExtractTest < MiniTest::Unit::TestCase
+class ZipFileExtractTest < MiniTest::Test
   include CommonZipFileFixture
-  EXTRACTED_FILENAME = "extEntry"
+  EXTRACTED_FILENAME = "test/data/generated/extEntry"
   ENTRY_TO_EXTRACT, *REMAINING_ENTRIES = TEST_ZIP.entry_names.reverse
 
   def setup
diff --git a/test/file_split_test.rb b/test/file_split_test.rb
--- a/test/file_split_test.rb
+++ b/test/file_split_test.rb
@@ -1,9 +1,9 @@
 require 'test_helper'
 
-class ZipFileSplitTest < MiniTest::Unit::TestCase
+class ZipFileSplitTest < MiniTest::Test
   TEST_ZIP = TestZipFile::TEST_ZIP2.clone
   TEST_ZIP.zip_name = "large_zip_file.zip"
-  EXTRACTED_FILENAME = "test/data/generated/extEntry"
+  EXTRACTED_FILENAME = "test/data/generated/extEntrySplit"
   UNSPLITTED_FILENAME = "test/data/generated/unsplitted.zip"
   ENTRY_TO_EXTRACT = TEST_ZIP.entry_names.first
 
diff --git a/test/file_test.rb b/test/file_test.rb
--- a/test/file_test.rb
+++ b/test/file_test.rb
@@ -1,9 +1,12 @@
 require 'test_helper'
 
 
-class ZipFileTest < MiniTest::Unit::TestCase
+class ZipFileTest < MiniTest::Test
   include CommonZipFileFixture
 
+  OK_DELETE_FILE = 'test/data/generated/okToDelete.txt'
+  OK_DELETE_MOVED_FILE = 'test/data/generated/okToDeleteMoved.txt'
+
   def teardown
     ::Zip.write_zip64_support = false
   end
@@ -87,19 +90,17 @@ def test_get_output_stream
   end
 
   def test_cleans_up_tempfiles_after_close
-    comment = "a short comment"
-
     zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
     zf.get_output_stream("myFile") do |os|
       @tempfile_path = os.path
       os.write "myFile contains just this"
     end
 
-    assert_equal(true, File.exists?(@tempfile_path))
+    assert_equal(true, File.exist?(@tempfile_path))
 
     zf.close
 
-    assert_equal(false, File.exists?(@tempfile_path))
+    assert_equal(false, File.exist?(@tempfile_path))
   end
 
   def test_add
@@ -386,13 +387,13 @@ def test_write_buffer
   # can delete the file you used to add the entry to the zip file
   # with
   def test_commitUseZipEntry
-    FileUtils.cp(TestFiles::RANDOM_ASCII_FILE1, "okToDelete.txt")
+    FileUtils.cp(TestFiles::RANDOM_ASCII_FILE1, OK_DELETE_FILE)
     zf = ::Zip::File.open(TEST_ZIP.zip_name)
-    zf.add("okToDelete.txt", "okToDelete.txt")
+    zf.add("okToDelete.txt", OK_DELETE_FILE)
     assert_contains(zf, "okToDelete.txt")
     zf.commit
-    File.rename("okToDelete.txt", "okToDeleteMoved.txt")
-    assert_contains(zf, "okToDelete.txt", "okToDeleteMoved.txt")
+    File.rename(OK_DELETE_FILE, OK_DELETE_MOVED_FILE)
+    assert_contains(zf, "okToDelete.txt", OK_DELETE_MOVED_FILE)
   end
 
 #  def test_close
diff --git a/test/filesystem/dir_iterator_test.rb b/test/filesystem/dir_iterator_test.rb
--- a/test/filesystem/dir_iterator_test.rb
+++ b/test/filesystem/dir_iterator_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/filesystem'
 
-class ZipFsDirIteratorTest < MiniTest::Unit::TestCase
+class ZipFsDirIteratorTest < MiniTest::Test
 
   FILENAME_ARRAY = [ "f1", "f2", "f3", "f4", "f5", "f6"  ]
 
diff --git a/test/filesystem/directory_test.rb b/test/filesystem/directory_test.rb
--- a/test/filesystem/directory_test.rb
+++ b/test/filesystem/directory_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/filesystem'
 
-class ZipFsDirectoryTest < MiniTest::Unit::TestCase
+class ZipFsDirectoryTest < MiniTest::Test
   TEST_ZIP = "test/data/generated/zipWithDirs_copy.zip"
 
   def setup
diff --git a/test/filesystem/file_mutating_test.rb b/test/filesystem/file_mutating_test.rb
--- a/test/filesystem/file_mutating_test.rb
+++ b/test/filesystem/file_mutating_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/filesystem'
 
-class ZipFsFileMutatingTest < MiniTest::Unit::TestCase
+class ZipFsFileMutatingTest < MiniTest::Test
   TEST_ZIP = "test/data/generated/zipWithDirs_copy.zip"
   def setup
     FileUtils.cp("test/data/zipWithDirs.zip", TEST_ZIP)
diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb
--- a/test/filesystem/file_nonmutating_test.rb
+++ b/test/filesystem/file_nonmutating_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/filesystem'
 
-class ZipFsFileNonmutatingTest < MiniTest::Unit::TestCase
+class ZipFsFileNonmutatingTest < MiniTest::Test
   def setup
     @zipsha = Digest::SHA1.file("test/data/zipWithDirs.zip")
     @zip_file = ::Zip::File.new("test/data/zipWithDirs.zip")
diff --git a/test/filesystem/file_stat_test.rb b/test/filesystem/file_stat_test.rb
--- a/test/filesystem/file_stat_test.rb
+++ b/test/filesystem/file_stat_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/filesystem'
 
-class ZipFsFileStatTest < MiniTest::Unit::TestCase
+class ZipFsFileStatTest < MiniTest::Test
 
   def setup
     @zip_file = ::Zip::File.new("test/data/zipWithDirs.zip")
diff --git a/test/inflater_test.rb b/test/inflater_test.rb
--- a/test/inflater_test.rb
+++ b/test/inflater_test.rb
@@ -1,5 +1,5 @@
 require 'test_helper'
-class InflaterTest < MiniTest::Unit::TestCase
+class InflaterTest < MiniTest::Test
   include DecompressorTests
 
   def setup
diff --git a/test/input_stream_test.rb b/test/input_stream_test.rb
--- a/test/input_stream_test.rb
+++ b/test/input_stream_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class ZipInputStreamTest < MiniTest::Unit::TestCase
+class ZipInputStreamTest < MiniTest::Test
   include AssertEntry
 
   def test_new
diff --git a/test/ioextras/abstract_input_stream_test.rb b/test/ioextras/abstract_input_stream_test.rb
--- a/test/ioextras/abstract_input_stream_test.rb
+++ b/test/ioextras/abstract_input_stream_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/ioextras'
 
-class AbstractInputStreamTest < MiniTest::Unit::TestCase
+class AbstractInputStreamTest < MiniTest::Test
   # AbstractInputStream subclass that provides a read method
 
   TEST_LINES = ["Hello world#{$/}",
diff --git a/test/ioextras/abstract_output_stream_test.rb b/test/ioextras/abstract_output_stream_test.rb
--- a/test/ioextras/abstract_output_stream_test.rb
+++ b/test/ioextras/abstract_output_stream_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/ioextras'
 
-class AbstractOutputStreamTest < MiniTest::Unit::TestCase
+class AbstractOutputStreamTest < MiniTest::Test
   class TestOutputStream
     include ::Zip::IOExtras::AbstractOutputStream
 
diff --git a/test/ioextras/fake_io_test.rb b/test/ioextras/fake_io_test.rb
--- a/test/ioextras/fake_io_test.rb
+++ b/test/ioextras/fake_io_test.rb
@@ -1,7 +1,7 @@
 require 'test_helper'
 require 'zip/ioextras'
 
-class FakeIOTest < MiniTest::Unit::TestCase
+class FakeIOTest < MiniTest::Test
   class FakeIOUsingClass
     include ::Zip::IOExtras::FakeIO
   end
diff --git a/test/local_entry_test.rb b/test/local_entry_test.rb
--- a/test/local_entry_test.rb
+++ b/test/local_entry_test.rb
@@ -1,6 +1,9 @@
 require 'test_helper'
 
-class ZipLocalEntryTest < MiniTest::Unit::TestCase
+class ZipLocalEntryTest < MiniTest::Test
+
+  CEH_FILE = 'test/data/generated/centralEntryHeader.bin'
+  LEH_FILE = 'test/data/generated/localEntryHeader.bin'
 
   def teardown
     ::Zip.write_zip64_support = false
@@ -54,8 +57,8 @@ def test_writeEntry
     entry = ::Zip::Entry.new("file.zip", "entryName", "my little comment",
                              "thisIsSomeExtraInformation", 100, 987654,
                              ::Zip::Entry::DEFLATED, 400)
-    write_to_file("localEntryHeader.bin", "centralEntryHeader.bin", entry)
-    entryReadLocal, entryReadCentral = read_from_file("localEntryHeader.bin", "centralEntryHeader.bin")
+    write_to_file(LEH_FILE, CEH_FILE, entry)
+    entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
     assert(entryReadCentral.extra['Zip64Placeholder'].nil?, 'zip64 placeholder should not be used in central directory')
     compare_local_entry_headers(entry, entryReadLocal)
     compare_c_dir_entry_headers(entry, entryReadCentral)
@@ -66,8 +69,8 @@ def test_writeEntryWithZip64
     entry = ::Zip::Entry.new("file.zip", "entryName", "my little comment",
                              "thisIsSomeExtraInformation", 100, 987654,
                              ::Zip::Entry::DEFLATED, 400)
-    write_to_file("localEntryHeader.bin", "centralEntryHeader.bin", entry)
-    entryReadLocal, entryReadCentral = read_from_file("localEntryHeader.bin", "centralEntryHeader.bin")
+    write_to_file(LEH_FILE, CEH_FILE, entry)
+    entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
     assert(entryReadLocal.extra['Zip64Placeholder'], 'zip64 placeholder should be used in local file header')
     entryReadLocal.extra.delete('Zip64Placeholder') # it was removed when writing the c_dir_entry, so remove from compare
     assert(entryReadCentral.extra['Zip64Placeholder'].nil?, 'zip64 placeholder should not be used in central directory')
@@ -81,8 +84,8 @@ def test_write64Entry
                              "malformed extra field because why not",
                              0x7766554433221100, 0xDEADBEEF, ::Zip::Entry::DEFLATED,
                              0x9988776655443322)
-    write_to_file("localEntryHeader.bin", "centralEntryHeader.bin", entry)
-    entryReadLocal, entryReadCentral = read_from_file("localEntryHeader.bin", "centralEntryHeader.bin")
+    write_to_file(LEH_FILE, CEH_FILE, entry)
+    entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
     compare_local_entry_headers(entry, entryReadLocal)
     compare_c_dir_entry_headers(entry, entryReadCentral)
   end
@@ -106,9 +109,9 @@ def test_rewriteLocalHeader64
   def test_readLocalOffset
     entry = ::Zip::Entry.new("file.zip", "entryName")
     entry.local_header_offset = 12345
-    ::File.open('centralEntryHeader.bin', 'wb') { |f| entry.write_c_dir_entry(f) }
+    ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
     read_entry = nil
-    ::File.open('centralEntryHeader.bin', 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) }
+    ::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) }
     compare_c_dir_entry_headers(entry, read_entry)
   end
 
@@ -116,9 +119,9 @@ def test_read64LocalOffset
     ::Zip.write_zip64_support = true
     entry = ::Zip::Entry.new("file.zip", "entryName")
     entry.local_header_offset = 0x0123456789ABCDEF
-    ::File.open('centralEntryHeader.bin', 'wb') { |f| entry.write_c_dir_entry(f) }
+    ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
     read_entry = nil
-    ::File.open('centralEntryHeader.bin', 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) }
+    ::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) }
     compare_c_dir_entry_headers(entry, read_entry)
   end
 
diff --git a/test/output_stream_test.rb b/test/output_stream_test.rb
--- a/test/output_stream_test.rb
+++ b/test/output_stream_test.rb
@@ -1,10 +1,10 @@
 require 'test_helper'
 
-class ZipOutputStreamTest < MiniTest::Unit::TestCase
+class ZipOutputStreamTest < MiniTest::Test
   include AssertEntry
 
   TEST_ZIP = TestZipFile::TEST_ZIP2.clone
-  TEST_ZIP.zip_name = "output.zip"
+  TEST_ZIP.zip_name = "test/data/generated/output.zip"
 
   def test_new
     zos = ::Zip::OutputStream.new(TEST_ZIP.zip_name)
@@ -99,7 +99,7 @@ def test_chained_put_into_next_entry
 
   def assert_i_o_error_in_closed_stream
     assert_raises(IOError) {
-      zos = ::Zip::OutputStream.new("test_putOnClosedStream.zip")
+      zos = ::Zip::OutputStream.new("test/data/generated/test_putOnClosedStream.zip")
       zos.close
       yield zos
     }
diff --git a/test/pass_thru_compressor_test.rb b/test/pass_thru_compressor_test.rb
--- a/test/pass_thru_compressor_test.rb
+++ b/test/pass_thru_compressor_test.rb
@@ -1,10 +1,10 @@
 require 'test_helper'
 
-class PassThruCompressorTest < MiniTest::Unit::TestCase
+class PassThruCompressorTest < MiniTest::Test
   include CrcTest
 
   def test_size
-    File.open("test/dummy.txt", "wb") {
+    File.open("test/data/generated/dummy.txt", "wb") {
         |file|
       compressor = ::Zip::PassThruCompressor.new(file)
 
diff --git a/test/pass_thru_decompressor_test.rb b/test/pass_thru_decompressor_test.rb
--- a/test/pass_thru_decompressor_test.rb
+++ b/test/pass_thru_decompressor_test.rb
@@ -1,5 +1,5 @@
 require 'test_helper'
-class PassThruDecompressorTest < MiniTest::Unit::TestCase
+class PassThruDecompressorTest < MiniTest::Test
   include DecompressorTests
 
   def setup
diff --git a/test/settings_test.rb b/test/settings_test.rb
--- a/test/settings_test.rb
+++ b/test/settings_test.rb
@@ -1,9 +1,10 @@
 require 'test_helper'
 
-class ZipSettingsTest < MiniTest::Unit::TestCase
+class ZipSettingsTest < MiniTest::Test
   # TODO Refactor out into common test module
   include CommonZipFileFixture
-  TEST_OUT_NAME = "emptyOutDir"
+
+  TEST_OUT_NAME = "test/data/generated/emptyOutDir"
 
   def setup
     super
diff --git a/test/test_helper.rb b/test/test_helper.rb
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -9,7 +9,7 @@
 TestFiles.create_test_files
 TestZipFile.create_test_zips
 
-::MiniTest::Unit.after_tests do
+::MiniTest.after_run do
   FileUtils.rm_rf('test/data/generated')
 end
 
diff --git a/test/unicode_file_names_and_comments_test.rb b/test/unicode_file_names_and_comments_test.rb
--- a/test/unicode_file_names_and_comments_test.rb
+++ b/test/unicode_file_names_and_comments_test.rb
@@ -2,7 +2,7 @@
 
 require 'test_helper'
 
-class ZipUnicodeFileNamesAndComments < MiniTest::Unit::TestCase
+class ZipUnicodeFileNamesAndComments < MiniTest::Test
 
   FILENAME = File.join(File.dirname(__FILE__), "test1.zip")
 
diff --git a/test/zip64_full_test.rb b/test/zip64_full_test.rb
--- a/test/zip64_full_test.rb
+++ b/test/zip64_full_test.rb
@@ -7,7 +7,7 @@
 # test zip64 support for real, by actually exceeding the 32-bit size/offset limits
 # this test does not, of course, run with the normal unit tests! ;)
 
-  class Zip64FullTest < MiniTest::Unit::TestCase
+  class Zip64FullTest < MiniTest::Test
     def prepareTestFile(test_filename)
       ::File.delete(test_filename) if ::File.exist?(test_filename)
       return test_filename
diff --git a/test/zip64_support_test.rb b/test/zip64_support_test.rb
--- a/test/zip64_support_test.rb
+++ b/test/zip64_support_test.rb
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class Zip64SupportTest < MiniTest::Unit::TestCase
+class Zip64SupportTest < MiniTest::Test
   TEST_FILE = File.join(File.dirname(__FILE__), 'data', 'zip64-sample.zip')
 
   def test_open_zip64_file