Sha256: 8e70cec226efcf8393e8ccf24e2d64062b5d0b5bc40fa7f861883a0294051a59

Contents?: true

Size: 1.33 KB

Versions: 59

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'

class ZipFileExtractDirectoryTest < MiniTest::Test
  include CommonZipFileFixture

  TEST_OUT_NAME = 'test/data/generated/emptyOutDir'

  def open_zip(&aProc)
    assert(!aProc.nil?)
    ::Zip::File.open(TestZipFile::TEST_ZIP4.zip_name, &aProc)
  end

  def extract_test_dir(&aProc)
    open_zip do |zf|
      zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
    end
  end

  def setup
    super

    Dir.rmdir(TEST_OUT_NAME) if File.directory? TEST_OUT_NAME
    File.delete(TEST_OUT_NAME) if File.exist? TEST_OUT_NAME
  end

  def test_extract_directory
    extract_test_dir
    assert(File.directory?(TEST_OUT_NAME))
  end

  def test_extract_directory_exists_as_dir
    Dir.mkdir TEST_OUT_NAME
    extract_test_dir
    assert(File.directory?(TEST_OUT_NAME))
  end

  def test_extract_directory_exists_as_file
    File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
    assert_raises(::Zip::DestinationFileExistsError) { extract_test_dir }
  end

  def test_extract_directory_exists_as_file_overwrite
    File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
    gotCalled = false
    extract_test_dir do |entry, destPath|
      gotCalled = true
      assert_equal(TEST_OUT_NAME, destPath)
      assert(entry.directory?)
      true
    end
    assert(gotCalled)
    assert(File.directory?(TEST_OUT_NAME))
  end
end

Version data entries

59 entries across 47 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/rubyzip-1.3.0/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.3/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/file_extract_directory_test.rb
rubyzip-1.3.0 test/file_extract_directory_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/file_extract_directory_test.rb
rubyzip-1.2.4 test/file_extract_directory_test.rb
rubyzip-1.2.3 test/file_extract_directory_test.rb
tdiary-5.0.13 vendor/bundle/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
tdiary-5.0.12.1 vendor/bundle/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.1/test/file_extract_directory_test.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/file_extract_directory_test.rb