Skip to content

Commit

Permalink
Add tests from #182 for testing tempfile as IO for OutputStream::writ…
Browse files Browse the repository at this point in the history
…e_buffer
  • Loading branch information
simonoff committed Feb 2, 2015
1 parent 44bab72 commit 002959f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/file_test.rb
Expand Up @@ -535,10 +535,12 @@ def test_streaming
end

data = nil
Zip::File.open_buffer(File.binread(zname)) do |zipfile|
zipfile.each do |entry|
next unless entry.name =~ /README.md/
data = zipfile.read(entry)
File.open(zname, 'rb') do |f|
Zip::File.open_buffer(f) do |zipfile|
zipfile.each do |entry|
next unless entry.name =~ /README.md/
data = zipfile.read(entry)
end
end
end
assert data
Expand Down
15 changes: 15 additions & 0 deletions test/output_stream_test.rb
Expand Up @@ -32,6 +32,21 @@ def test_write_buffer
assert_test_zip_contents(TEST_ZIP)
end

def test_write_buffer_with_temp_file
tmp_file = Tempfile.new('')

::Zip::OutputStream.write_buffer(tmp_file) do |zos|
zos.comment = TEST_ZIP.comment
write_test_zip(zos)
end

tmp_file.rewind
File.open(TEST_ZIP.zip_name, 'wb') { |f| f.write(tmp_file.read) }
tmp_file.unlink

assert_test_zip_contents(TEST_ZIP)
end

def test_writingToClosedStream
assert_i_o_error_in_closed_stream { |zos| zos << "hello world" }
assert_i_o_error_in_closed_stream { |zos| zos.puts "hello world" }
Expand Down

0 comments on commit 002959f

Please sign in to comment.