-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathbasic_zip_file_test.rb
50 lines (40 loc) · 1.46 KB
/
basic_zip_file_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
require 'test_helper'
class BasicZipFileTest < MiniTest::Test
include AssertEntry
def setup
@zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
end
def test_entries
expected_entry_names = TestZipFile::TEST_ZIP2.entry_names
actual_entry_names = @zip_file.entries.entries.map(&:name)
assert_equal(expected_entry_names.sort, actual_entry_names.sort)
end
def test_each
expected_entry_names = TestZipFile::TEST_ZIP2.entry_names
actual_entry_names = []
@zip_file.each { |entry| actual_entry_names << entry.name }
assert_equal(expected_entry_names.sort, actual_entry_names.sort)
end
def test_foreach
expected_entry_names = TestZipFile::TEST_ZIP2.entry_names
actual_entry_names = []
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) { |entry| actual_entry_names << entry.name }
assert_equal(expected_entry_names.sort, actual_entry_names.sort)
end
def test_get_input_stream
expected_entry_names = TestZipFile::TEST_ZIP2.entry_names
actual_entry_names = []
@zip_file.each do |entry|
actual_entry_names << entry.name
assert_entry(entry.name, @zip_file.get_input_stream(entry), entry.name)
end
assert_equal(expected_entry_names.sort, actual_entry_names.sort)
end
def test_get_input_stream_block
name = @zip_file.entries.first.name
@zip_file.get_input_stream(name) do |zis|
assert_entry_contents_for_stream(name, zis, name)
end
end
end