8000 Add tests from #182 for testing tempfile as IO for OutputStream::writ… · rubyzip/rubyzip@002959f · GitHub
[go: up one dir, main page]

Skip to content

Commit 002959f

Browse files
committed
Add tests from #182 for testing tempfile as IO for OutputStream::write_buffer
1 parent 44bab72 commit 002959f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

test/file_test.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,12 @@ def test_streaming
535535
end
536536

537537
data = nil
538-
Zip::File.open_buffer(File.binread(zname)) do |zipfile|
539-
zipfile.each do |entry|
540-
next unless entry.name =~ /README.md/
541-
data = zipfile.read(entry)
538+
File.open(zname, 'rb') do |f|
539+
Zip::File.open_buffer(f) do |zipfile|
540+
zipfile.each do |entry|
541+
next unless entry.name =~ /README.md/
542+
data = zipfile.read(entry)
543+
end
542544
end
543545
end
544546
assert data

test/output_stream_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ def test_write_buffer
3232
assert_test_zip_contents(TEST_ZIP)
3333
end
3434

35+
def test_write_buffer_with_temp_file
36+
tmp_file = Tempfile.new('')
37+
38+
::Zip::OutputStream.write_buffer(tmp_file) do |zos|
39+
zos.comment = TEST_ZIP.comment
40+
write_test_zip(zos)
41+
end
42+
43+
tmp_file.rewind
44+
File.open(TEST_ZIP.zip_name, 'wb') { |f| f.write(tmp_file.read) }
45+
tmp_file.unlink
46+
47+
assert_test_zip_contents(TEST_ZIP)
48+
end
49+
3550
def test_writingToClosedStream
3651
assert_i_o_error_in_closed_stream { |zos| zos << "hello world" }
3752
assert_i_o_error_in_closed_stream { |zos| zos.puts "hello world" }

0 commit comments

Comments
 (0)
0