rubyzip 1.1.7 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +87 -45
  3. data/Rakefile +3 -4
  4. data/lib/zip.rb +11 -5
  5. data/lib/zip/central_directory.rb +8 -8
  6. data/lib/zip/compressor.rb +1 -2
  7. data/lib/zip/constants.rb +5 -5
  8. data/lib/zip/crypto/null_encryption.rb +4 -6
  9. data/lib/zip/crypto/traditional_encryption.rb +5 -5
  10. data/lib/zip/decompressor.rb +3 -3
  11. data/lib/zip/deflater.rb +8 -6
  12. data/lib/zip/dos_time.rb +5 -6
  13. data/lib/zip/entry.rb +120 -128
  14. data/lib/zip/entry_set.rb +14 -14
  15. data/lib/zip/errors.rb +1 -0
  16. data/lib/zip/extra_field.rb +8 -8
  17. data/lib/zip/extra_field/generic.rb +8 -8
  18. data/lib/zip/extra_field/ntfs.rb +14 -16
  19. data/lib/zip/extra_field/old_unix.rb +9 -10
  20. data/lib/zip/extra_field/universal_time.rb +14 -14
  21. data/lib/zip/extra_field/unix.rb +8 -9
  22. data/lib/zip/extra_field/zip64.rb +12 -11
  23. data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
  24. data/lib/zip/file.rb +81 -81
  25. data/lib/zip/filesystem.rb +144 -143
  26. data/lib/zip/inflater.rb +5 -5
  27. data/lib/zip/input_stream.rb +22 -13
  28. data/lib/zip/ioextras.rb +1 -3
  29. data/lib/zip/ioextras/abstract_input_stream.rb +6 -10
  30. data/lib/zip/ioextras/abstract_output_stream.rb +3 -5
  31. data/lib/zip/null_compressor.rb +2 -2
  32. data/lib/zip/null_decompressor.rb +3 -3
  33. data/lib/zip/null_input_stream.rb +0 -0
  34. data/lib/zip/output_stream.rb +13 -14
  35. data/lib/zip/pass_thru_compressor.rb +4 -4
  36. data/lib/zip/pass_thru_decompressor.rb +3 -4
  37. data/lib/zip/streamable_directory.rb +2 -2
  38. data/lib/zip/streamable_stream.rb +3 -3
  39. data/lib/zip/version.rb +1 -1
  40. data/samples/example.rb +29 -39
  41. data/samples/example_filesystem.rb +16 -18
  42. data/samples/example_recursive.rb +31 -25
  43. data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
  44. data/samples/qtzip.rb +18 -27
  45. data/samples/write_simple.rb +12 -13
  46. data/samples/zipfind.rb +26 -34
  47. data/test/basic_zip_file_test.rb +11 -15
  48. data/test/case_sensitivity_test.rb +69 -0
  49. data/test/central_directory_entry_test.rb +32 -36
  50. data/test/central_directory_test.rb +46 -50
  51. data/test/crypto/null_encryption_test.rb +8 -4
  52. data/test/crypto/traditional_encryption_test.rb +5 -5
  53. data/test/data/gpbit3stored.zip +0 -0
  54. data/test/data/notzippedruby.rb +1 -1
  55. data/test/data/oddExtraField.zip +0 -0
  56. data/test/data/path_traversal/Makefile +10 -0
  57. data/test/data/path_traversal/jwilk/README.md +5 -0
  58. data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
  59. data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
  60. data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
  61. data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
  62. data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
  63. data/test/data/path_traversal/jwilk/relative0.zip +0 -0
  64. data/test/data/path_traversal/jwilk/relative2.zip +0 -0
  65. data/test/data/path_traversal/jwilk/symlink.zip +0 -0
  66. data/test/data/path_traversal/relative1.zip +0 -0
  67. data/test/data/path_traversal/tilde.zip +0 -0
  68. data/test/data/path_traversal/tuzovakaoff/README.md +3 -0
  69. data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
  70. data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
  71. data/test/data/rubycode.zip +0 -0
  72. data/test/data/test.xls +0 -0
  73. data/test/deflater_test.rb +10 -12
  74. data/test/encryption_test.rb +2 -2
  75. data/test/entry_set_test.rb +50 -25
  76. data/test/entry_test.rb +76 -87
  77. data/test/errors_test.rb +1 -2
  78. data/test/extra_field_test.rb +19 -21
  79. data/test/file_extract_directory_test.rb +12 -14
  80. data/test/file_extract_test.rb +33 -40
  81. data/test/file_permissions_test.rb +65 -0
  82. data/test/file_split_test.rb +24 -27
  83. data/test/file_test.rb +266 -179
  84. data/test/filesystem/dir_iterator_test.rb +13 -17
  85. data/test/filesystem/directory_test.rb +101 -93
  86. data/test/filesystem/file_mutating_test.rb +52 -65
  87. data/test/filesystem/file_nonmutating_test.rb +223 -229
  88. data/test/filesystem/file_stat_test.rb +17 -19
  89. data/test/gentestfiles.rb +54 -62
  90. data/test/inflater_test.rb +1 -1
  91. data/test/input_stream_test.rb +52 -40
  92. data/test/ioextras/abstract_input_stream_test.rb +22 -23
  93. data/test/ioextras/abstract_output_stream_test.rb +33 -33
  94. data/test/ioextras/fake_io_test.rb +1 -1
  95. data/test/local_entry_test.rb +36 -38
  96. data/test/output_stream_test.rb +20 -21
  97. data/test/pass_thru_compressor_test.rb +5 -6
  98. data/test/pass_thru_decompressor_test.rb +0 -1
  99. data/test/path_traversal_test.rb +141 -0
  100. data/test/samples/example_recursive_test.rb +37 -0
  101. data/test/settings_test.rb +18 -15
  102. data/test/test_helper.rb +52 -46
  103. data/test/unicode_file_names_and_comments_test.rb +17 -7
  104. data/test/zip64_full_test.rb +10 -12
  105. data/test/zip64_support_test.rb +0 -1
  106. metadata +94 -65
@@ -2,8 +2,7 @@ require 'test_helper'
2
2
  require 'zip/filesystem'
3
3
 
4
4
  class ZipFsDirIteratorTest < MiniTest::Test
5
-
6
- FILENAME_ARRAY = [ "f1", "f2", "f3", "f4", "f5", "f6" ]
5
+ FILENAME_ARRAY = %w[f1 f2 f3 f4 f5 f6]
7
6
 
8
7
  def setup
9
8
  @dirIt = ::Zip::FileSystem::ZipFsDirIterator.new(FILENAME_ARRAY)
@@ -11,22 +10,21 @@ class ZipFsDirIteratorTest < MiniTest::Test
11
10
 
12
11
  def test_close
13
12
  @dirIt.close
14
- assert_raises(IOError, "closed directory") {
13
+ assert_raises(IOError, 'closed directory') do
15
14
  @dirIt.each { |e| p e }
16
- }
17
- assert_raises(IOError, "closed directory") {
15
+ end
16
+ assert_raises(IOError, 'closed directory') do
18
17
  @dirIt.read
19
- }
20
- assert_raises(IOError, "closed directory") {
18
+ end
19
+ assert_raises(IOError, 'closed directory') do
21
20
  @dirIt.rewind
22
- }
23
- assert_raises(IOError, "closed directory") {
21
+ end
22
+ assert_raises(IOError, 'closed directory') do
24
23
  @dirIt.seek(0)
25
- }
26
- assert_raises(IOError, "closed directory") {
24
+ end
25
+ assert_raises(IOError, 'closed directory') do
27
26
  @dirIt.tell
28
- }
29
-
27
+ end
30
28
  end
31
29
 
32
30
  def test_each
@@ -35,10 +33,9 @@ class ZipFsDirIteratorTest < MiniTest::Test
35
33
  end
36
34
 
37
35
  def test_read
38
- FILENAME_ARRAY.size.times {
39
- |i|
36
+ FILENAME_ARRAY.size.times do |i|
40
37
  assert_equal(FILENAME_ARRAY[i], @dirIt.read)
41
- }
38
+ end
42
39
  end
43
40
 
44
41
  def test_rewind
@@ -58,5 +55,4 @@ class ZipFsDirIteratorTest < MiniTest::Test
58
55
  @dirIt.seek(pos)
59
56
  assert_equal(valAtPos, @dirIt.read)
60
57
  end
61
-
62
58
  end
@@ -2,130 +2,138 @@ require 'test_helper'
2
2
  require 'zip/filesystem'
3
3
 
4
4
  class ZipFsDirectoryTest < MiniTest::Test
5
- TEST_ZIP = "test/data/generated/zipWithDirs_copy.zip"
5
+ TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
6
+ GLOB_TEST_ZIP = 'test/data/globTest.zip'
6
7
 
7
8
  def setup
8
- FileUtils.cp("test/data/zipWithDirs.zip", TEST_ZIP)
9
+ FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
9
10
  end
10
11
 
11
12
  def test_delete
12
- ::Zip::File.open(TEST_ZIP) {
13
- |zf|
14
- assert_raises(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") {
15
- zf.dir.delete("NoSuchFile.txt")
16
- }
17
- assert_raises(Errno::EINVAL, "Invalid argument - file1") {
18
- zf.dir.delete("file1")
19
- }
20
- assert(zf.file.exists?("dir1"))
21
- zf.dir.delete("dir1")
22
- assert(! zf.file.exists?("dir1"))
23
- }
13
+ ::Zip::File.open(TEST_ZIP) do |zf|
14
+ assert_raises(Errno::ENOENT, 'No such file or directory - NoSuchFile.txt') do
15
+ zf.dir.delete('NoSuchFile.txt')
16
+ end
17
+ assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
18
+ zf.dir.delete('file1')
19
+ end
20
+ assert(zf.file.exists?('dir1'))
21
+ zf.dir.delete('dir1')
22
+ assert(!zf.file.exists?('dir1'))
23
+ end
24
24
  end
25
25
 
26
26
  def test_mkdir
27
- ::Zip::File.open(TEST_ZIP) {
28
- |zf|
29
- assert_raises(Errno::EEXIST, "File exists - dir1") {
30
- zf.dir.mkdir("file1")
31
- }
32
- assert_raises(Errno::EEXIST, "File exists - dir1") {
33
- zf.dir.mkdir("dir1")
34
- }
35
- assert(!zf.file.exists?("newDir"))
36
- zf.dir.mkdir("newDir")
37
- assert(zf.file.directory?("newDir"))
38
- assert(!zf.file.exists?("newDir2"))
39
- zf.dir.mkdir("newDir2", 3485)
40
- assert(zf.file.directory?("newDir2"))
41
- }
27
+ ::Zip::File.open(TEST_ZIP) do |zf|
28
+ assert_raises(Errno::EEXIST, 'File exists - dir1') do
29
+ zf.dir.mkdir('file1')
30
+ end
31
+ assert_raises(Errno::EEXIST, 'File exists - dir1') do
32
+ zf.dir.mkdir('dir1')
33
+ end
34
+ assert(!zf.file.exists?('newDir'))
35
+ zf.dir.mkdir('newDir')
36
+ assert(zf.file.directory?('newDir'))
37
+ assert(!zf.file.exists?('newDir2'))
38
+ zf.dir.mkdir('newDir2', 3485)
39
+ assert(zf.file.directory?('newDir2'))
40
+ end
42
41
  end
43
42
 
44
43
  def test_pwd_chdir_entries
45
- ::Zip::File.open(TEST_ZIP) {
46
- |zf|
47
- assert_equal("/", zf.dir.pwd)
48
-
49
- assert_raises(Errno::ENOENT, "No such file or directory - no such dir") {
50
- zf.dir.chdir "no such dir"
51
- }
52
-
53
- assert_raises(Errno::EINVAL, "Invalid argument - file1") {
54
- zf.dir.chdir "file1"
55
- }
56
-
57
- assert_equal(["dir1", "dir2", "file1"].sort, zf.dir.entries(".").sort)
58
- zf.dir.chdir "dir1"
59
- assert_equal("/dir1", zf.dir.pwd)
60
- assert_equal(["dir11", "file11", "file12"], zf.dir.entries(".").sort)
61
-
62
- zf.dir.chdir "../dir2/dir21"
63
- assert_equal("/dir2/dir21", zf.dir.pwd)
64
- assert_equal(["dir221"].sort, zf.dir.entries(".").sort)
65
- }
44
+ ::Zip::File.open(TEST_ZIP) do |zf|
45
+ assert_equal('/', zf.dir.pwd)
46
+
47
+ assert_raises(Errno::ENOENT, 'No such file or directory - no such dir') do
48
+ zf.dir.chdir 'no such dir'
49
+ end
50
+
51
+ assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
52
+ zf.dir.chdir 'file1'
53
+ end
54
+
55
+ assert_equal(%w[dir1 dir2 file1].sort, zf.dir.entries('.').sort)
56
+ zf.dir.chdir 'dir1'
57
+ assert_equal('/dir1', zf.dir.pwd)
58
+ assert_equal(%w[dir11 file11 file12], zf.dir.entries('.').sort)
59
+
60
+ zf.dir.chdir '../dir2/dir21'
61
+ assert_equal('/dir2/dir21', zf.dir.pwd)
62
+ assert_equal(['dir221'].sort, zf.dir.entries('.').sort)
63
+ end
66
64
  end
67
65
 
68
66
  def test_foreach
69
- ::Zip::File.open(TEST_ZIP) {
70
- |zf|
71
-
67
+ ::Zip::File.open(TEST_ZIP) do |zf|
72
68
  blockCalled = false
73
- assert_raises(Errno::ENOENT, "No such file or directory - noSuchDir") {
74
- zf.dir.foreach("noSuchDir") { |e| blockCalled = true }
75
- }
76
- assert(! blockCalled)
69
+ assert_raises(Errno::ENOENT, 'No such file or directory - noSuchDir') do
70
+ zf.dir.foreach('noSuchDir') { |_e| blockCalled = true }
71
+ end
72
+ assert(!blockCalled)
77
73
 
78
- assert_raises(Errno::ENOTDIR, "Not a directory - file1") {
79
- zf.dir.foreach("file1") { |e| blockCalled = true }
80
- }
81
- assert(! blockCalled)
74
+ assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
75
+ zf.dir.foreach('file1') { |_e| blockCalled = true }
76
+ end
77
+ assert(!blockCalled)
82
78
 
83
79
  entries = []
84
- zf.dir.foreach(".") { |e| entries << e }
85
- assert_equal(["dir1", "dir2", "file1"].sort, entries.sort)
80
+ zf.dir.foreach('.') { |e| entries << e }
81
+ assert_equal(%w[dir1 dir2 file1].sort, entries.sort)
86
82
 
87
83
  entries = []
88
- zf.dir.foreach("dir1") { |e| entries << e }
89
- assert_equal(["dir11", "file11", "file12"], entries.sort)
90
- }
84
+ zf.dir.foreach('dir1') { |e| entries << e }
85
+ assert_equal(%w[dir11 file11 file12], entries.sort)
86
+ end
91
87
  end
92
88
 
93
89
  def test_chroot
94
- ::Zip::File.open(TEST_ZIP) {
95
- |zf|
96
- assert_raises(NotImplementedError) {
90
+ ::Zip::File.open(TEST_ZIP) do |zf|
91
+ assert_raises(NotImplementedError) do
97
92
  zf.dir.chroot
98
- }
99
- }
93
+ end
94
+ end
100
95
  end
101
96
 
102
- # Globbing not supported yet
103
- #def test_glob
104
- # # test alias []-operator too
105
- # fail "implement test"
106
- #end
97
+ def test_glob
98
+ globbed_files = [
99
+ 'globTest/foo/bar/baz/foo.txt',
100
+ 'globTest/foo.txt',
101
+ 'globTest/food.txt'
102
+ ]
103
+
104
+ ::Zip::File.open(GLOB_TEST_ZIP) do |zf|
105
+ zf.dir.glob('**/*.txt') do |f|
106
+ assert globbed_files.include?(f.name)
107
+ end
108
+
109
+ zf.dir.glob('globTest/foo/**/*.txt') do |f|
110
+ assert_equal globbed_files[0], f.name
111
+ end
112
+
113
+ zf.dir.chdir('globTest/foo')
114
+ zf.dir.glob('**/*.txt') do |f|
115
+ assert_equal globbed_files[0], f.name
116
+ end
117
+ end
118
+ end
107
119
 
108
120
  def test_open_new
109
- ::Zip::File.open(TEST_ZIP) {
110
- |zf|
121
+ ::Zip::File.open(TEST_ZIP) do |zf|
122
+ assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
123
+ zf.dir.new('file1')
124
+ end
111
125
 
112
- assert_raises(Errno::ENOTDIR, "Not a directory - file1") {
113
- zf.dir.new("file1")
114
- }
126
+ assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
127
+ zf.dir.new('noSuchFile')
128
+ end
115
129
 
116
- assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
117
- zf.dir.new("noSuchFile")
118
- }
119
-
120
- d = zf.dir.new(".")
121
- assert_equal(["file1", "dir1", "dir2"].sort, d.entries.sort)
130
+ d = zf.dir.new('.')
131
+ assert_equal(%w[file1 dir1 dir2].sort, d.entries.sort)
122
132
  d.close
123
133
 
124
- zf.dir.open("dir1") {
125
- |dir|
126
- assert_equal(["dir11", "file11", "file12"].sort, dir.entries.sort)
127
- }
128
- }
134
+ zf.dir.open('dir1') do |dir|
135
+ assert_equal(%w[dir11 file11 file12].sort, dir.entries.sort)
136
+ end
137
+ end
129
138
  end
130
-
131
139
  end
@@ -2,13 +2,12 @@ require 'test_helper'
2
2
  require 'zip/filesystem'
3
3
 
4
4
  class ZipFsFileMutatingTest < MiniTest::Test
5
- TEST_ZIP = "test/data/generated/zipWithDirs_copy.zip"
5
+ TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
6
6
  def setup
7
- FileUtils.cp("test/data/zipWithDirs.zip", TEST_ZIP)
7
+ FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
8
8
  end
9
9
 
10
- def teardown
11
- end
10
+ def teardown; end
12
11
 
13
12
  def test_delete
14
13
  do_test_delete_or_unlink(:delete)
@@ -19,82 +18,70 @@ class ZipFsFileMutatingTest < MiniTest::Test
19
18
  end
20
19
 
21
20
  def test_open_write
22
- ::Zip::File.open(TEST_ZIP) {
23
- |zf|
24
-
25
- zf.file.open("test_open_write_entry", "w") {
26
- |f|
21
+ ::Zip::File.open(TEST_ZIP) do |zf|
22
+ zf.file.open('test_open_write_entry', 'w') do |f|
27
23
  f.write "This is what I'm writing"
28
- }
24
+ end
29
25
  assert_equal("This is what I'm writing",
30
- zf.file.read("test_open_write_entry"))
26
+ zf.file.read('test_open_write_entry'))
31
27
 
32
28
  # Test with existing entry
33
- zf.file.open("file1", "wb") { #also check that 'b' option is ignored
34
- |f|
29
+ zf.file.open('file1', 'wb') do |f| # also check that 'b' option is ignored
35
30
  f.write "This is what I'm writing too"
36
- }
31
+ end
37
32
  assert_equal("This is what I'm writing too",
38
- zf.file.read("file1"))
39
- }
33
+ zf.file.read('file1'))
34
+ end
40
35
  end
41
36
 
42
37
  def test_rename
43
- ::Zip::File.open(TEST_ZIP) {
44
- |zf|
45
- assert_raises(Errno::ENOENT, "") {
46
- zf.file.rename("NoSuchFile", "bimse")
47
- }
48
- zf.file.rename("file1", "newNameForFile1")
49
- }
50
-
51
- ::Zip::File.open(TEST_ZIP) {
52
- |zf|
53
- assert(! zf.file.exists?("file1"))
54
- assert(zf.file.exists?("newNameForFile1"))
55
- }
38
+ ::Zip::File.open(TEST_ZIP) do |zf|
39
+ assert_raises(Errno::ENOENT, '') do
40
+ zf.file.rename('NoSuchFile', 'bimse')
41
+ end
42
+ zf.file.rename('file1', 'newNameForFile1')
43
+ end
44
+
45
+ ::Zip::File.open(TEST_ZIP) do |zf|
46
+ assert(!zf.file.exists?('file1'))
47
+ assert(zf.file.exists?('newNameForFile1'))
48
+ end
56
49
  end
57
50
 
58
51
  def test_chmod
59
- ::Zip::File.open(TEST_ZIP) {
60
- |zf|
52
+ ::Zip::File.open(TEST_ZIP) do |zf|
53
+ zf.file.chmod(0o765, 'file1')
54
+ end
61
55
 
62
- zf.file.chmod(0765, "file1")
63
- }
64
-
65
- ::Zip::File.open(TEST_ZIP) {
66
- |zf|
67
- assert_equal(0100765, zf.file.stat("file1").mode)
68
- }
56
+ ::Zip::File.open(TEST_ZIP) do |zf|
57
+ assert_equal(0o100765, zf.file.stat('file1').mode)
58
+ end
69
59
  end
70
60
 
71
61
  def do_test_delete_or_unlink(symbol)
72
- ::Zip::File.open(TEST_ZIP) {
73
- |zf|
74
- assert(zf.file.exists?("dir2/dir21/dir221/file2221"))
75
- zf.file.send(symbol, "dir2/dir21/dir221/file2221")
76
- assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
77
-
78
- assert(zf.file.exists?("dir1/file11"))
79
- assert(zf.file.exists?("dir1/file12"))
80
- zf.file.send(symbol, "dir1/file11", "dir1/file12")
81
- assert(! zf.file.exists?("dir1/file11"))
82
- assert(! zf.file.exists?("dir1/file12"))
83
-
84
- assert_raises(Errno::ENOENT) { zf.file.send(symbol, "noSuchFile") }
85
- assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11") }
86
- assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11/") }
87
- }
88
-
89
- ::Zip::File.open(TEST_ZIP) {
90
- |zf|
91
- assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
92
- assert(! zf.file.exists?("dir1/file11"))
93
- assert(! zf.file.exists?("dir1/file12"))
94
-
95
- assert(zf.file.exists?("dir1/dir11"))
96
- assert(zf.file.exists?("dir1/dir11/"))
97
- }
62
+ ::Zip::File.open(TEST_ZIP) do |zf|
63
+ assert(zf.file.exists?('dir2/dir21/dir221/file2221'))
64
+ zf.file.send(symbol, 'dir2/dir21/dir221/file2221')
65
+ assert(!zf.file.exists?('dir2/dir21/dir221/file2221'))
66
+
67
+ assert(zf.file.exists?('dir1/file11'))
68
+ assert(zf.file.exists?('dir1/file12'))
69
+ zf.file.send(symbol, 'dir1/file11', 'dir1/file12')
70
+ assert(!zf.file.exists?('dir1/file11'))
71
+ assert(!zf.file.exists?('dir1/file12'))
72
+
73
+ assert_raises(Errno::ENOENT) { zf.file.send(symbol, 'noSuchFile') }
74
+ assert_raises(Errno::EISDIR) { zf.file.send(symbol, 'dir1/dir11') }
75
+ assert_raises(Errno::EISDIR) { zf.file.send(symbol, 'dir1/dir11/') }
76
+ end
77
+
78
+ ::Zip::File.open(TEST_ZIP) do |zf|
79
+ assert(!zf.file.exists?('dir2/dir21/dir221/file2221'))
80
+ assert(!zf.file.exists?('dir1/file11'))
81
+ assert(!zf.file.exists?('dir1/file12'))
82
+
83
+ assert(zf.file.exists?('dir1/dir11'))
84
+ assert(zf.file.exists?('dir1/dir11/'))
85
+ end
98
86
  end
99
-
100
87
  end
@@ -3,71 +3,68 @@ require 'zip/filesystem'
3
3
 
4
4
  class ZipFsFileNonmutatingTest < MiniTest::Test
5
5
  def setup
6
- @zipsha = Digest::SHA1.file("test/data/zipWithDirs.zip")
7
- @zip_file = ::Zip::File.new("test/data/zipWithDirs.zip")
6
+ @zipsha = Digest::SHA1.file('test/data/zipWithDirs.zip')
7
+ @zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
8
8
  end
9
9
 
10
10
  def teardown
11
11
  @zip_file.close if @zip_file
12
- assert_equal(@zipsha, Digest::SHA1.file("test/data/zipWithDirs.zip"))
12
+ assert_equal(@zipsha, Digest::SHA1.file('test/data/zipWithDirs.zip'))
13
13
  end
14
14
 
15
15
  def test_umask
16
16
  assert_equal(::File.umask, @zip_file.file.umask)
17
- @zip_file.file.umask(0006)
17
+ @zip_file.file.umask(0o006)
18
18
  end
19
19
 
20
20
  def test_exists?
21
- assert(! @zip_file.file.exists?("notAFile"))
22
- assert(@zip_file.file.exists?("file1"))
23
- assert(@zip_file.file.exists?("dir1"))
24
- assert(@zip_file.file.exists?("dir1/"))
25
- assert(@zip_file.file.exists?("dir1/file12"))
26
- assert(@zip_file.file.exist?("dir1/file12")) # notice, tests exist? alias of exists? !
21
+ assert(!@zip_file.file.exists?('notAFile'))
22
+ assert(@zip_file.file.exists?('file1'))
23
+ assert(@zip_file.file.exists?('dir1'))
24
+ assert(@zip_file.file.exists?('dir1/'))
25
+ assert(@zip_file.file.exists?('dir1/file12'))
26
+ assert(@zip_file.file.exist?('dir1/file12')) # notice, tests exist? alias of exists? !
27
27
 
28
- @zip_file.dir.chdir "dir1/"
29
- assert(!@zip_file.file.exists?("file1"))
30
- assert(@zip_file.file.exists?("file12"))
28
+ @zip_file.dir.chdir 'dir1/'
29
+ assert(!@zip_file.file.exists?('file1'))
30
+ assert(@zip_file.file.exists?('file12'))
31
31
  end
32
32
 
33
33
  def test_open_read
34
34
  blockCalled = false
35
- @zip_file.file.open("file1", "r") {
36
- |f|
35
+ @zip_file.file.open('file1', 'r') do |f|
37
36
  blockCalled = true
38
37
  assert_equal("this is the entry 'file1' in my test archive!",
39
- f.readline.chomp)
40
- }
38
+ f.readline.chomp)
39
+ end
41
40
  assert(blockCalled)
42
41
 
43
42
  blockCalled = false
44
- @zip_file.file.open("file1", "rb") { # test binary flag is ignored
45
- |f|
43
+ @zip_file.file.open('file1', 'rb') do |f| # test binary flag is ignored
46
44
  blockCalled = true
47
45
  assert_equal("this is the entry 'file1' in my test archive!",
48
- f.readline.chomp)
49
- }
46
+ f.readline.chomp)
47
+ end
50
48
  assert(blockCalled)
51
49
 
52
50
  blockCalled = false
53
- @zip_file.dir.chdir "dir2"
54
- @zip_file.file.open("file21", "r") {
55
- |f|
51
+ @zip_file.dir.chdir 'dir2'
52
+ @zip_file.file.open('file21', 'r') do |f|
56
53
  blockCalled = true
57
54
  assert_equal("this is the entry 'dir2/file21' in my test archive!",
58
- f.readline.chomp)
59
- }
55
+ f.readline.chomp)
56
+ end
60
57
  assert(blockCalled)
61
- @zip_file.dir.chdir "/"
58
+ @zip_file.dir.chdir '/'
62
59
 
63
- assert_raises(Errno::ENOENT) {
64
- @zip_file.file.open("noSuchEntry")
65
- }
60
+ assert_raises(Errno::ENOENT) do
61
+ @zip_file.file.open('noSuchEntry')
62
+ end
66
63
 
67
64
  begin
68
- is = @zip_file.file.open("file1")
65
+ is = @zip_file.file.open('file1')
69
66
  assert_equal("this is the entry 'file1' in my test archive!",
70
- is.readline.chomp)
67
+ is.readline.chomp)
71
68
  ensure
72
69
  is.close if is
73
70
  end
@@ -75,109 +72,107 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
75
72
 
76
73
  def test_new
77
74
  begin
78
- is = @zip_file.file.new("file1")
75
+ is = @zip_file.file.new('file1')
79
76
  assert_equal("this is the entry 'file1' in my test archive!",
80
- is.readline.chomp)
77
+ is.readline.chomp)
81
78
  ensure
82
79
  is.close if is
83
80
  end
84
81
  begin
85
- is = @zip_file.file.new("file1") {
86
- fail "should not call block"
87
- }
82
+ is = @zip_file.file.new('file1') do
83
+ fail 'should not call block'
84
+ end
88
85
  ensure
89
86
  is.close if is
90
87
  end
91
88
  end
92
89
 
93
90
  def test_symlink
94
- assert_raises(NotImplementedError) {
95
- @zip_file.file.symlink("file1", "aSymlink")
96
- }
91
+ assert_raises(NotImplementedError) do
92
+ @zip_file.file.symlink('file1', 'aSymlink')
93
+ end
97
94
  end
98
95
 
99
96
  def test_size
100
- assert_raises(Errno::ENOENT) { @zip_file.file.size("notAFile") }
101
- assert_equal(72, @zip_file.file.size("file1"))
102
- assert_equal(0, @zip_file.file.size("dir2/dir21"))
97
+ assert_raises(Errno::ENOENT) { @zip_file.file.size('notAFile') }
98
+ assert_equal(72, @zip_file.file.size('file1'))
99
+ assert_equal(0, @zip_file.file.size('dir2/dir21'))
103
100
 
104
- assert_equal(72, @zip_file.file.stat("file1").size)
105
- assert_equal(0, @zip_file.file.stat("dir2/dir21").size)
101
+ assert_equal(72, @zip_file.file.stat('file1').size)
102
+ assert_equal(0, @zip_file.file.stat('dir2/dir21').size)
106
103
  end
107
104
 
108
105
  def test_size?
109
- assert_equal(nil, @zip_file.file.size?("notAFile"))
110
- assert_equal(72, @zip_file.file.size?("file1"))
111
- assert_equal(nil, @zip_file.file.size?("dir2/dir21"))
106
+ assert_nil(@zip_file.file.size?('notAFile'))
107
+ assert_equal(72, @zip_file.file.size?('file1'))
108
+ assert_nil(@zip_file.file.size?('dir2/dir21'))
112
109
 
113
- assert_equal(72, @zip_file.file.stat("file1").size?)
114
- assert_equal(nil, @zip_file.file.stat("dir2/dir21").size?)
110
+ assert_equal(72, @zip_file.file.stat('file1').size?)
111
+ assert_nil(@zip_file.file.stat('dir2/dir21').size?)
115
112
  end
116
113
 
117
-
118
114
  def test_file?
119
- assert(@zip_file.file.file?("file1"))
120
- assert(@zip_file.file.file?("dir2/file21"))
121
- assert(! @zip_file.file.file?("dir1"))
122
- assert(! @zip_file.file.file?("dir1/dir11"))
115
+ assert(@zip_file.file.file?('file1'))
116
+ assert(@zip_file.file.file?('dir2/file21'))
117
+ assert(!@zip_file.file.file?('dir1'))
118
+ assert(!@zip_file.file.file?('dir1/dir11'))
123
119
 
124
- assert(@zip_file.file.stat("file1").file?)
125
- assert(@zip_file.file.stat("dir2/file21").file?)
126
- assert(! @zip_file.file.stat("dir1").file?)
127
- assert(! @zip_file.file.stat("dir1/dir11").file?)
120
+ assert(@zip_file.file.stat('file1').file?)
121
+ assert(@zip_file.file.stat('dir2/file21').file?)
122
+ assert(!@zip_file.file.stat('dir1').file?)
123
+ assert(!@zip_file.file.stat('dir1/dir11').file?)
128
124
  end
129
125
 
130
126
  include ExtraAssertions
131
127
 
132
128
  def test_dirname
133
- assert_forwarded(File, :dirname, "retVal", "a/b/c/d") {
134
- @zip_file.file.dirname("a/b/c/d")
135
- }
129
+ assert_forwarded(File, :dirname, 'retVal', 'a/b/c/d') do
130
+ @zip_file.file.dirname('a/b/c/d')
131
+ end
136
132
  end
137
133
 
138
134
  def test_basename
139
- assert_forwarded(File, :basename, "retVal", "a/b/c/d") {
140
- @zip_file.file.basename("a/b/c/d")
141
- }
135
+ assert_forwarded(File, :basename, 'retVal', 'a/b/c/d') do
136
+ @zip_file.file.basename('a/b/c/d')
137
+ end
142
138
  end
143
139
 
144
140
  def test_split
145
- assert_forwarded(File, :split, "retVal", "a/b/c/d") {
146
- @zip_file.file.split("a/b/c/d")
147
- }
141
+ assert_forwarded(File, :split, 'retVal', 'a/b/c/d') do
142
+ @zip_file.file.split('a/b/c/d')
143
+ end
148
144
  end
149
145
 
150
146
  def test_join
151
- assert_equal("a/b/c", @zip_file.file.join("a/b", "c"))
152
- assert_equal("a/b/c/d", @zip_file.file.join("a/b", "c/d"))
153
- assert_equal("/c/d", @zip_file.file.join("", "c/d"))
154
- assert_equal("a/b/c/d", @zip_file.file.join("a", "b", "c", "d"))
147
+ assert_equal('a/b/c', @zip_file.file.join('a/b', 'c'))
148
+ assert_equal('a/b/c/d', @zip_file.file.join('a/b', 'c/d'))
149
+ assert_equal('/c/d', @zip_file.file.join('', 'c/d'))
150
+ assert_equal('a/b/c/d', @zip_file.file.join('a', 'b', 'c', 'd'))
155
151
  end
156
152
 
157
153
  def test_utime
158
154
  t_now = ::Zip::DOSTime.now
159
- t_bak = @zip_file.file.mtime("file1")
160
- @zip_file.file.utime(t_now, "file1")
161
- assert_equal(t_now, @zip_file.file.mtime("file1"))
162
- @zip_file.file.utime(t_bak, "file1")
163
- assert_equal(t_bak, @zip_file.file.mtime("file1"))
155
+ t_bak = @zip_file.file.mtime('file1')
156
+ @zip_file.file.utime(t_now, 'file1')
157
+ assert_equal(t_now, @zip_file.file.mtime('file1'))
158
+ @zip_file.file.utime(t_bak, 'file1')
159
+ assert_equal(t_bak, @zip_file.file.mtime('file1'))
164
160
  end
165
161
 
166
-
167
162
  def assert_always_false(operation)
168
- assert(! @zip_file.file.send(operation, "noSuchFile"))
169
- assert(! @zip_file.file.send(operation, "file1"))
170
- assert(! @zip_file.file.send(operation, "dir1"))
171
- assert(! @zip_file.file.stat("file1").send(operation))
172
- assert(! @zip_file.file.stat("dir1").send(operation))
163
+ assert(!@zip_file.file.send(operation, 'noSuchFile'))
164
+ assert(!@zip_file.file.send(operation, 'file1'))
165
+ assert(!@zip_file.file.send(operation, 'dir1'))
166
+ assert(!@zip_file.file.stat('file1').send(operation))
167
+ assert(!@zip_file.file.stat('dir1').send(operation))
173
168
  end
174
169
 
175
170
  def assert_true_if_entry_exists(operation)
176
- assert(! @zip_file.file.send(operation, "noSuchFile"))
177
- assert(@zip_file.file.send(operation, "file1"))
178
- assert(@zip_file.file.send(operation, "dir1"))
179
- assert(@zip_file.file.stat("file1").send(operation))
180
- assert(@zip_file.file.stat("dir1").send(operation))
171
+ assert(!@zip_file.file.send(operation, 'noSuchFile'))
172
+ assert(@zip_file.file.send(operation, 'file1'))
173
+ assert(@zip_file.file.send(operation, 'dir1'))
174
+ assert(@zip_file.file.stat('file1').send(operation))
175
+ assert(@zip_file.file.stat('dir1').send(operation))
181
176
  end
182
177
 
183
178
  def test_pipe?
@@ -201,167 +196,164 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
201
196
  end
202
197
 
203
198
  def test_truncate
204
- assert_raises(StandardError, "truncate not supported") {
205
- @zip_file.file.truncate("file1", 100)
206
- }
199
+ assert_raises(StandardError, 'truncate not supported') do
200
+ @zip_file.file.truncate('file1', 100)
201
+ end
207
202
  end
208
203
 
209
- def assert_e_n_o_e_n_t(operation, args = ["NoSuchFile"])
210
- assert_raises(Errno::ENOENT) {
204
+ def assert_e_n_o_e_n_t(operation, args = ['NoSuchFile'])
205
+ assert_raises(Errno::ENOENT) do
211
206
  @zip_file.file.send(operation, *args)
212
- }
207
+ end
213
208
  end
214
209
 
215
210
  def test_ftype
216
211
  assert_e_n_o_e_n_t(:ftype)
217
- assert_equal("file", @zip_file.file.ftype("file1"))
218
- assert_equal("directory", @zip_file.file.ftype("dir1/dir11"))
219
- assert_equal("directory", @zip_file.file.ftype("dir1/dir11/"))
212
+ assert_equal('file', @zip_file.file.ftype('file1'))
213
+ assert_equal('directory', @zip_file.file.ftype('dir1/dir11'))
214
+ assert_equal('directory', @zip_file.file.ftype('dir1/dir11/'))
220
215
  end
221
216
 
222
217
  def test_link
223
- assert_raises(NotImplementedError) {
224
- @zip_file.file.link("file1", "someOtherString")
225
- }
218
+ assert_raises(NotImplementedError) do
219
+ @zip_file.file.link('file1', 'someOtherString')
220
+ end
226
221
  end
227
222
 
228
223
  def test_directory?
229
- assert(! @zip_file.file.directory?("notAFile"))
230
- assert(! @zip_file.file.directory?("file1"))
231
- assert(! @zip_file.file.directory?("dir1/file11"))
232
- assert(@zip_file.file.directory?("dir1"))
233
- assert(@zip_file.file.directory?("dir1/"))
234
- assert(@zip_file.file.directory?("dir2/dir21"))
224
+ assert(!@zip_file.file.directory?('notAFile'))
225
+ assert(!@zip_file.file.directory?('file1'))
226
+ assert(!@zip_file.file.directory?('dir1/file11'))
227
+ assert(@zip_file.file.directory?('dir1'))
228
+ assert(@zip_file.file.directory?('dir1/'))
229
+ assert(@zip_file.file.directory?('dir2/dir21'))
235
230
 
236
- assert(! @zip_file.file.stat("file1").directory?)
237
- assert(! @zip_file.file.stat("dir1/file11").directory?)
238
- assert(@zip_file.file.stat("dir1").directory?)
239
- assert(@zip_file.file.stat("dir1/").directory?)
240
- assert(@zip_file.file.stat("dir2/dir21").directory?)
231
+ assert(!@zip_file.file.stat('file1').directory?)
232
+ assert(!@zip_file.file.stat('dir1/file11').directory?)
233
+ assert(@zip_file.file.stat('dir1').directory?)
234
+ assert(@zip_file.file.stat('dir1/').directory?)
235
+ assert(@zip_file.file.stat('dir2/dir21').directory?)
241
236
  end
242
237
 
243
238
  def test_chown
244
- assert_equal(2, @zip_file.file.chown(1,2, "dir1", "file1"))
245
- assert_equal(1, @zip_file.file.stat("dir1").uid)
246
- assert_equal(2, @zip_file.file.stat("dir1").gid)
247
- assert_equal(2, @zip_file.file.chown(nil, nil, "dir1", "file1"))
239
+ assert_equal(2, @zip_file.file.chown(1, 2, 'dir1', 'file1'))
240
+ assert_equal(1, @zip_file.file.stat('dir1').uid)
241
+ assert_equal(2, @zip_file.file.stat('dir1').gid)
242
+ assert_equal(2, @zip_file.file.chown(nil, nil, 'dir1', 'file1'))
248
243
  end
249
244
 
250
245
  def test_zero?
251
- assert(! @zip_file.file.zero?("notAFile"))
252
- assert(! @zip_file.file.zero?("file1"))
253
- assert(@zip_file.file.zero?("dir1"))
246
+ assert(!@zip_file.file.zero?('notAFile'))
247
+ assert(!@zip_file.file.zero?('file1'))
248
+ assert(@zip_file.file.zero?('dir1'))
254
249
  blockCalled = false
255
- ::Zip::File.open("test/data/generated/5entry.zip") {
256
- |zf|
250
+ ::Zip::File.open('test/data/generated/5entry.zip') do |zf|
257
251
  blockCalled = true
258
- assert(zf.file.zero?("test/data/generated/empty.txt"))
259
- }
252
+ assert(zf.file.zero?('test/data/generated/empty.txt'))
253
+ end
260
254
  assert(blockCalled)
261
255
 
262
- assert(! @zip_file.file.stat("file1").zero?)
263
- assert(@zip_file.file.stat("dir1").zero?)
256
+ assert(!@zip_file.file.stat('file1').zero?)
257
+ assert(@zip_file.file.stat('dir1').zero?)
264
258
  blockCalled = false
265
- ::Zip::File.open("test/data/generated/5entry.zip") {
266
- |zf|
259
+ ::Zip::File.open('test/data/generated/5entry.zip') do |zf|
267
260
  blockCalled = true
268
- assert(zf.file.stat("test/data/generated/empty.txt").zero?)
269
- }
261
+ assert(zf.file.stat('test/data/generated/empty.txt').zero?)
262
+ end
270
263
  assert(blockCalled)
271
264
  end
272
265
 
273
266
  def test_expand_path
274
- ::Zip::File.open("test/data/zipWithDirs.zip") {
275
- |zf|
276
- assert_equal("/", zf.file.expand_path("."))
277
- zf.dir.chdir "dir1"
278
- assert_equal("/dir1", zf.file.expand_path("."))
279
- assert_equal("/dir1/file12", zf.file.expand_path("file12"))
280
- assert_equal("/", zf.file.expand_path(".."))
281
- assert_equal("/dir2/dir21", zf.file.expand_path("../dir2/dir21"))
282
- }
267
+ ::Zip::File.open('test/data/zipWithDirs.zip') do |zf|
268
+ assert_equal('/', zf.file.expand_path('.'))
269
+ zf.dir.chdir 'dir1'
270
+ assert_equal('/dir1', zf.file.expand_path('.'))
271
+ assert_equal('/dir1/file12', zf.file.expand_path('file12'))
272
+ assert_equal('/', zf.file.expand_path('..'))
273
+ assert_equal('/dir2/dir21', zf.file.expand_path('../dir2/dir21'))
274
+ end
283
275
  end
284
276
 
285
277
  def test_mtime
286
- assert_equal(::Zip::DOSTime.at(1027694306),
287
- @zip_file.file.mtime("dir2/file21"))
288
- assert_equal(::Zip::DOSTime.at(1027690863),
289
- @zip_file.file.mtime("dir2/dir21"))
290
- assert_raises(Errno::ENOENT) {
291
- @zip_file.file.mtime("noSuchEntry")
292
- }
278
+ assert_equal(::Zip::DOSTime.at(1_027_694_306),
279
+ @zip_file.file.mtime('dir2/file21'))
280
+ assert_equal(::Zip::DOSTime.at(1_027_690_863),
281
+ @zip_file.file.mtime('dir2/dir21'))
282
+ assert_raises(Errno::ENOENT) do
283
+ @zip_file.file.mtime('noSuchEntry')
284
+ end
293
285
 
294
- assert_equal(::Zip::DOSTime.at(1027694306),
295
- @zip_file.file.stat("dir2/file21").mtime)
296
- assert_equal(::Zip::DOSTime.at(1027690863),
297
- @zip_file.file.stat("dir2/dir21").mtime)
286
+ assert_equal(::Zip::DOSTime.at(1_027_694_306),
287
+ @zip_file.file.stat('dir2/file21').mtime)
288
+ assert_equal(::Zip::DOSTime.at(1_027_690_863),
289
+ @zip_file.file.stat('dir2/dir21').mtime)
298
290
  end
299
291
 
300
292
  def test_ctime
301
- assert_nil(@zip_file.file.ctime("file1"))
302
- assert_nil(@zip_file.file.stat("file1").ctime)
293
+ assert_nil(@zip_file.file.ctime('file1'))
294
+ assert_nil(@zip_file.file.stat('file1').ctime)
303
295
  end
304
296
 
305
297
  def test_atime
306
- assert_nil(@zip_file.file.atime("file1"))
307
- assert_nil(@zip_file.file.stat("file1").atime)
298
+ assert_nil(@zip_file.file.atime('file1'))
299
+ assert_nil(@zip_file.file.stat('file1').atime)
308
300
  end
309
301
 
310
302
  def test_ntfs_time
311
- ::Zip::File.open("test/data/ntfs.zip") do |zf|
312
- t = ::Zip::DOSTime.at(1410496497.405178)
313
- assert_equal(zf.file.mtime("data.txt"), t)
314
- assert_equal(zf.file.atime("data.txt"), t)
315
- assert_equal(zf.file.ctime("data.txt"), t)
303
+ ::Zip::File.open('test/data/ntfs.zip') do |zf|
304
+ t = ::Zip::DOSTime.at(1_410_496_497.405178)
305
+ assert_equal(zf.file.mtime('data.txt'), t)
306
+ assert_equal(zf.file.atime('data.txt'), t)
307
+ assert_equal(zf.file.ctime('data.txt'), t)
316
308
  end
317
309
  end
318
310
 
319
311
  def test_readable?
320
- assert(! @zip_file.file.readable?("noSuchFile"))
321
- assert(@zip_file.file.readable?("file1"))
322
- assert(@zip_file.file.readable?("dir1"))
323
- assert(@zip_file.file.stat("file1").readable?)
324
- assert(@zip_file.file.stat("dir1").readable?)
312
+ assert(!@zip_file.file.readable?('noSuchFile'))
313
+ assert(@zip_file.file.readable?('file1'))
314
+ assert(@zip_file.file.readable?('dir1'))
315
+ assert(@zip_file.file.stat('file1').readable?)
316
+ assert(@zip_file.file.stat('dir1').readable?)
325
317
  end
326
318
 
327
319
  def test_readable_real?
328
- assert(! @zip_file.file.readable_real?("noSuchFile"))
329
- assert(@zip_file.file.readable_real?("file1"))
330
- assert(@zip_file.file.readable_real?("dir1"))
331
- assert(@zip_file.file.stat("file1").readable_real?)
332
- assert(@zip_file.file.stat("dir1").readable_real?)
320
+ assert(!@zip_file.file.readable_real?('noSuchFile'))
321
+ assert(@zip_file.file.readable_real?('file1'))
322
+ assert(@zip_file.file.readable_real?('dir1'))
323
+ assert(@zip_file.file.stat('file1').readable_real?)
324
+ assert(@zip_file.file.stat('dir1').readable_real?)
333
325
  end
334
326
 
335
327
  def test_writable?
336
- assert(! @zip_file.file.writable?("noSuchFile"))
337
- assert(@zip_file.file.writable?("file1"))
338
- assert(@zip_file.file.writable?("dir1"))
339
- assert(@zip_file.file.stat("file1").writable?)
340
- assert(@zip_file.file.stat("dir1").writable?)
328
+ assert(!@zip_file.file.writable?('noSuchFile'))
329
+ assert(@zip_file.file.writable?('file1'))
330
+ assert(@zip_file.file.writable?('dir1'))
331
+ assert(@zip_file.file.stat('file1').writable?)
332
+ assert(@zip_file.file.stat('dir1').writable?)
341
333
  end
342
334
 
343
335
  def test_writable_real?
344
- assert(! @zip_file.file.writable_real?("noSuchFile"))
345
- assert(@zip_file.file.writable_real?("file1"))
346
- assert(@zip_file.file.writable_real?("dir1"))
347
- assert(@zip_file.file.stat("file1").writable_real?)
348
- assert(@zip_file.file.stat("dir1").writable_real?)
336
+ assert(!@zip_file.file.writable_real?('noSuchFile'))
337
+ assert(@zip_file.file.writable_real?('file1'))
338
+ assert(@zip_file.file.writable_real?('dir1'))
339
+ assert(@zip_file.file.stat('file1').writable_real?)
340
+ assert(@zip_file.file.stat('dir1').writable_real?)
349
341
  end
350
342
 
351
343
  def test_executable?
352
- assert(! @zip_file.file.executable?("noSuchFile"))
353
- assert(! @zip_file.file.executable?("file1"))
354
- assert(@zip_file.file.executable?("dir1"))
355
- assert(! @zip_file.file.stat("file1").executable?)
356
- assert(@zip_file.file.stat("dir1").executable?)
344
+ assert(!@zip_file.file.executable?('noSuchFile'))
345
+ assert(!@zip_file.file.executable?('file1'))
346
+ assert(@zip_file.file.executable?('dir1'))
347
+ assert(!@zip_file.file.stat('file1').executable?)
348
+ assert(@zip_file.file.stat('dir1').executable?)
357
349
  end
358
350
 
359
351
  def test_executable_real?
360
- assert(! @zip_file.file.executable_real?("noSuchFile"))
361
- assert(! @zip_file.file.executable_real?("file1"))
362
- assert(@zip_file.file.executable_real?("dir1"))
363
- assert(! @zip_file.file.stat("file1").executable_real?)
364
- assert(@zip_file.file.stat("dir1").executable_real?)
352
+ assert(!@zip_file.file.executable_real?('noSuchFile'))
353
+ assert(!@zip_file.file.executable_real?('file1'))
354
+ assert(@zip_file.file.executable_real?('dir1'))
355
+ assert(!@zip_file.file.stat('file1').executable_real?)
356
+ assert(@zip_file.file.stat('dir1').executable_real?)
365
357
  end
366
358
 
367
359
  def test_owned?
@@ -385,37 +377,37 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
385
377
  end
386
378
 
387
379
  def test_readlink
388
- assert_raises(NotImplementedError) {
389
- @zip_file.file.readlink("someString")
390
- }
380
+ assert_raises(NotImplementedError) do
381
+ @zip_file.file.readlink('someString')
382
+ end
391
383
  end
392
384
 
393
385
  def test_stat
394
- s = @zip_file.file.stat("file1")
386
+ s = @zip_file.file.stat('file1')
395
387
  assert(s.kind_of?(File::Stat)) # It pretends
396
- assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
397
- @zip_file.file.stat("noSuchFile")
398
- }
388
+ assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
389
+ @zip_file.file.stat('noSuchFile')
390
+ end
399
391
  end
400
392
 
401
393
  def test_lstat
402
- assert(@zip_file.file.lstat("file1").file?)
394
+ assert(@zip_file.file.lstat('file1').file?)
403
395
  end
404
396
 
405
397
  def test_pipe
406
- assert_raises(NotImplementedError) {
398
+ assert_raises(NotImplementedError) do
407
399
  @zip_file.file.pipe
408
- }
400
+ end
409
401
  end
410
402
 
411
403
  def test_foreach
412
- ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
404
+ ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
413
405
  ref = []
414
- File.foreach("test/data/file1.txt") { |e| ref << e }
406
+ File.foreach('test/data/file1.txt') { |e| ref << e }
415
407
  index = 0
416
408
 
417
- zf.file.foreach("test/data/file1.txt") do |l|
418
- #Ruby replaces \n with \r\n automatically on windows
409
+ zf.file.foreach('test/data/file1.txt') do |l|
410
+ # Ruby replaces \n with \r\n automatically on windows
419
411
  newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
420
412
  assert_equal(ref[index], newline)
421
413
  index = index.next
@@ -423,13 +415,13 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
423
415
  assert_equal(ref.size, index)
424
416
  end
425
417
 
426
- ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
418
+ ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
427
419
  ref = []
428
- File.foreach("test/data/file1.txt", " ") { |e| ref << e }
420
+ File.foreach('test/data/file1.txt', ' ') { |e| ref << e }
429
421
  index = 0
430
422
 
431
- zf.file.foreach("test/data/file1.txt", " ") do |l|
432
- #Ruby replaces \n with \r\n automatically on windows
423
+ zf.file.foreach('test/data/file1.txt', ' ') do |l|
424
+ # Ruby replaces \n with \r\n automatically on windows
433
425
  newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
434
426
  assert_equal(ref[index], newline)
435
427
  index = index.next
@@ -443,27 +435,27 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
443
435
  {
444
436
  'globTest/foo.txt' => ['globTest/foo.txt'],
445
437
  '*/foo.txt' => ['globTest/foo.txt'],
446
- '**/foo.txt' => ['globTest/foo.txt','globTest/foo/bar/baz/foo.txt'],
438
+ '**/foo.txt' => ['globTest/foo.txt', 'globTest/foo/bar/baz/foo.txt'],
447
439
  '*/foo/**/*.txt' => ['globTest/foo/bar/baz/foo.txt']
448
- }.each do |spec,expected_results|
440
+ }.each do |spec, expected_results|
449
441
  results = zf.glob(spec)
450
- assert results.all?{|entry| entry.is_a? ::Zip::Entry }
442
+ assert results.all? { |entry| entry.is_a? ::Zip::Entry }
451
443
 
452
444
  result_strings = results.map(&:to_s)
453
445
  missing_matches = expected_results - result_strings
454
446
  extra_matches = result_strings - expected_results
455
447
 
456
- assert extra_matches.empty?, %Q{spec #{spec.inspect} has extra results #{extra_matches.inspect}}
457
- assert missing_matches.empty?, %Q{spec #{spec.inspect} missing results #{missing_matches.inspect}}
448
+ assert extra_matches.empty?, "spec #{spec.inspect} has extra results #{extra_matches.inspect}"
449
+ assert missing_matches.empty?, "spec #{spec.inspect} missing results #{missing_matches.inspect}"
458
450
  end
459
451
  end
460
452
 
461
453
  ::Zip::File.open('test/data/globTest.zip') do |zf|
462
454
  results = []
463
455
  zf.glob('**/foo.txt') do |match|
464
- results << "<#{match.class.name}: #{match.to_s}>"
456
+ results << "<#{match.class.name}: #{match}>"
465
457
  end
466
- assert((not results.empty?), 'block not run, or run out of context')
458
+ assert(!results.empty?, 'block not run, or run out of context')
467
459
  assert_equal 2, results.size
468
460
  assert_operator results, :include?, '<Zip::Entry: globTest/foo.txt>'
469
461
  assert_operator results, :include?, '<Zip::Entry: globTest/foo/bar/baz/foo.txt>'
@@ -472,8 +464,8 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
472
464
 
473
465
  def test_popen
474
466
  if Zip::RUNNING_ON_WINDOWS
475
- #This is pretty much projectile vomit but it allows the test to be
476
- #run on windows also
467
+ # This is pretty much projectile vomit but it allows the test to be
468
+ # run on windows also
477
469
  system_dir = ::File.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '')
478
470
  zipfile_dir = @zip_file.file.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '')
479
471
  assert_equal(system_dir, zipfile_dir)
@@ -483,17 +475,17 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
483
475
  end
484
476
  end
485
477
 
486
- # Can be added later
487
- # def test_select
488
- # fail "implement test"
489
- # end
478
+ # Can be added later
479
+ # def test_select
480
+ # fail "implement test"
481
+ # end
490
482
 
491
483
  def test_readlines
492
- ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
493
- orig_file = ::File.readlines("test/data/file1.txt")
494
- zip_file = zf.file.readlines("test/data/file1.txt")
484
+ ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
485
+ orig_file = ::File.readlines('test/data/file1.txt')
486
+ zip_file = zf.file.readlines('test/data/file1.txt')
495
487
 
496
- #Ruby replaces \n with \r\n automatically on windows
488
+ # Ruby replaces \n with \r\n automatically on windows
497
489
  zip_file.each { |l| l.gsub!(/\r\n/, "\n") } if Zip::RUNNING_ON_WINDOWS
498
490
 
499
491
  assert_equal(orig_file, zip_file)
@@ -501,14 +493,16 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
501
493
  end
502
494
 
503
495
  def test_read
504
- ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
505
- orig_file = ::File.read("test/data/file1.txt")
506
-
507
- #Ruby replaces \n with \r\n automatically on windows
508
- zip_file = Zip::RUNNING_ON_WINDOWS ? \
509
- zf.file.read("test/data/file1.txt").gsub(/\r\n/, "\n") : zf.file.read("test/data/file1.txt")
496
+ ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
497
+ orig_file = ::File.read('test/data/file1.txt')
498
+
499
+ # Ruby replaces \n with \r\n automatically on windows
500
+ zip_file = if Zip::RUNNING_ON_WINDOWS
501
+ zf.file.read('test/data/file1.txt').gsub(/\r\n/, "\n")
502
+ else
503
+ zf.file.read('test/data/file1.txt')
504
+ end
510
505
  assert_equal(orig_file, zip_file)
511
506
  end
512
507
  end
513
-
514
508
  end