Return created zip file from Zip::File.open when supplied a block
This change is to match ruby zip’s behavior to core’s IO.open when supplied a block.
This commit is contained in:
parent
6b77562d32
commit
e3029d0b10
|
@ -97,6 +97,7 @@ module Zip
|
||||||
return zf unless block_given?
|
return zf unless block_given?
|
||||||
begin
|
begin
|
||||||
yield zf
|
yield zf
|
||||||
|
zf
|
||||||
ensure
|
ensure
|
||||||
zf.close
|
zf.close
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,18 @@ class ZipFileTest < MiniTest::Unit::TestCase
|
||||||
assert_equal(2, zfRead.entries.length)
|
assert_equal(2, zfRead.entries.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_open_with_block_returns_zip_file
|
||||||
|
srcFile = "test/data/file2.txt"
|
||||||
|
entryName = "newEntryName.rb"
|
||||||
|
assert(::File.exist?(srcFile))
|
||||||
|
created_file = ::Zip::File.open(EMPTY_FILENAME, ::Zip::File::CREATE) do |zf|
|
||||||
|
zf.add(entryName, srcFile)
|
||||||
|
end
|
||||||
|
|
||||||
|
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
||||||
|
assert_equal(created_file, zfRead)
|
||||||
|
end
|
||||||
|
|
||||||
def test_get_output_stream
|
def test_get_output_stream
|
||||||
entryCount = nil
|
entryCount = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||||
|
|
Loading…
Reference in New Issue