Class: ZipSettingsTest

Inherits:
MiniTest::Test
  • Object
show all
Includes:
CommonZipFileFixture
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb

Constant Summary collapse

TEST_OUT_NAME =
"test/data/generated/emptyOutDir"

Constants included from CommonZipFileFixture

CommonZipFileFixture::EMPTY_FILENAME, CommonZipFileFixture::TEST_ZIP

Instance Method Summary collapse

Methods included from AssertEntry

assert_contents, #assert_entry, #assert_entryContents, #assert_entryContentsForStream, #assert_next_entry, #assert_stream_contents, #assert_test_zip_contents

Instance Method Details

#extract_test_dir(&aProc) ⇒ Object



25
26
27
28
29
30
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 25

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

#open_zip(&aProc) ⇒ Object



20
21
22
23
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 20

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

#setupObject



9
10
11
12
13
14
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 9

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

#teardownObject



16
17
18
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 16

def teardown
  ::Zip.reset!
end

#test_false_continue_on_exists_procObject



45
46
47
48
49
50
51
52
53
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 45

def test_false_continue_on_exists_proc
  Zip.continue_on_exists_proc = false

  assert_raises(::Zip::EntryExistsError) do
    ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
      zf.add(zf.entries.first.name, "test/data/file2.txt")
    end
  end
end

#test_false_on_exists_procObject



39
40
41
42
43
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 39

def test_false_on_exists_proc
  Zip.on_exists_proc = false
  File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
  assert_raises(Zip::DestinationFileExistsError) { extract_test_dir }
end

#test_false_warn_invalid_dateObject



70
71
72
73
74
75
76
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 70

def test_false_warn_invalid_date
  test_file = File.join(File.dirname(__FILE__), 'data', 'WarnInvalidDate.zip')
  Zip.warn_invalid_date = false

  ::Zip::File.open(test_file) do |zf|
  end
end

#test_true_continue_on_exists_procObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 55

def test_true_continue_on_exists_proc
  Zip.continue_on_exists_proc = true

  replacedEntry = nil

  ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
    replacedEntry = zf.entries.first.name
    zf.add(replacedEntry, "test/data/file2.txt")
  end

  ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
    assert_contains(zf, replacedEntry, "test/data/file2.txt")
  end
end

#test_true_on_exists_procObject



32
33
34
35
36
37
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 32

def test_true_on_exists_proc
  Zip.on_exists_proc = true
  File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
  extract_test_dir
  assert(File.directory?(TEST_OUT_NAME))
end

#test_true_warn_invalid_dateObject



78
79
80
81
82
83
84
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb', line 78

def test_true_warn_invalid_date
  test_file = File.join(File.dirname(__FILE__), 'data', 'WarnInvalidDate.zip')
  Zip.warn_invalid_date = true

  ::Zip::File.open(test_file) do |zf|
  end
end