diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index db716f2..cfd974a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,19 +10,13 @@ require_relative "support/read_monitor" require_relative "support/managed_tempfile" -require_relative "support/zip_inspection" require_relative "support/chunked_encoding" require_relative "support/allocate_under_matcher" RSpec.configure do |config| - config.include ZipInspection config.include ChunkedEncoding config.after :each do ManagedTempfile.prune! end - - config.after :suite do - $stderr << $zip_inspection_buf.string if $zip_inspection_buf - end end diff --git a/spec/support/zip_inspection.rb b/spec/support/zip_inspection.rb deleted file mode 100644 index e3d45ff..0000000 --- a/spec/support/zip_inspection.rb +++ /dev/null @@ -1,15 +0,0 @@ -module ZipInspection - def inspect_zip_with_external_tool(path_to_zip) - return unless ENV["INSPECT_TEST_ZIPS"] - - zipinfo_path = "zipinfo" - $zip_inspection_buf ||= StringIO.new - $zip_inspection_buf.puts "\n" - # The only way to get at the RSpec example without using the block argument - $zip_inspection_buf.puts "Inspecting ZIP output of #{inspect}." - $zip_inspection_buf.puts 'Be aware that the zipinfo version on OSX is too \ - old to deal with Zip64.' - escaped_cmd = Shellwords.join([zipinfo_path, "-tlhvz", path_to_zip]) - $zip_inspection_buf.puts `#{escaped_cmd}` - end -end diff --git a/spec/zip_kit/output_enumerator_spec.rb b/spec/zip_kit/output_enumerator_spec.rb index de4edbc..1bbc141 100644 --- a/spec/zip_kit/output_enumerator_spec.rb +++ b/spec/zip_kit/output_enumerator_spec.rb @@ -2,7 +2,7 @@ describe ZipKit::OutputEnumerator do it "returns parts of the ZIP file when called via #each with immediate yield" do - output_buf = Tempfile.new("output") + output_buf = ManagedTempfile.new("output") file_body = Random.new.bytes(1024 * 1024 + 8981) @@ -34,7 +34,7 @@ end it "returns parts of the ZIP file when called using an Enumerator" do - output_buf = Tempfile.new("output") + output_buf = ManagedTempfile.new("output") file_body = Random.new.bytes(1024 * 1024 + 8981) diff --git a/spec/zip_kit/rack_body_spec.rb b/spec/zip_kit/rack_body_spec.rb index 4de6909..b7caeac 100644 --- a/spec/zip_kit/rack_body_spec.rb +++ b/spec/zip_kit/rack_body_spec.rb @@ -2,7 +2,7 @@ describe ZipKit::RackBody do it "is usable as a Rack response body, supports each()" do - output_buf = Tempfile.new("output") + output_buf = ManagedTempfile.new("output") file_body = Random.new.bytes(1024 * 1024 + 8981) diff --git a/spec/zip_kit/remote_io_spec.rb b/spec/zip_kit/remote_io_spec.rb index d919d48..fa54a8a 100644 --- a/spec/zip_kit/remote_io_spec.rb +++ b/spec/zip_kit/remote_io_spec.rb @@ -42,7 +42,7 @@ describe "#read" do before :each do - @buf = Tempfile.new("simulated-http") + @buf = ManagedTempfile.new("simulated-http") @buf.binmode 5.times { @buf << Random.new.bytes(1024 * 1024 * 3) } @buf.rewind diff --git a/spec/zip_kit/remote_uncap_spec.rb b/spec/zip_kit/remote_uncap_spec.rb index c53af6f..1a04282 100644 --- a/spec/zip_kit/remote_uncap_spec.rb +++ b/spec/zip_kit/remote_uncap_spec.rb @@ -38,12 +38,12 @@ it 'returns an array of remote entries that can be used to fetch the segments \ from within the ZIP' do - payload1 = Tempfile.new "payload1" + payload1 = ManagedTempfile.new "payload1" payload1 << Random.new.bytes((1024 * 1024 * 5) + 10) payload1.flush payload1.rewind - payload2 = Tempfile.new "payload2" + payload2 = ManagedTempfile.new "payload2" payload2 << Random.new.bytes(1024 * 1024 * 3) payload2.flush payload2.rewind @@ -79,11 +79,11 @@ end it "can cope with an empty file within the zip" do - payload1 = Tempfile.new "payload1" + payload1 = ManagedTempfile.new "payload1" payload1.flush payload1.rewind - payload2 = Tempfile.new "payload2" + payload2 = ManagedTempfile.new "payload2" payload2 << Random.new.bytes(1024) payload2.flush payload2.rewind diff --git a/spec/zip_kit/streamer_spec.rb b/spec/zip_kit/streamer_spec.rb index 1236cee..5dc9747 100644 --- a/spec/zip_kit/streamer_spec.rb +++ b/spec/zip_kit/streamer_spec.rb @@ -104,7 +104,7 @@ def stream_with_just_write.write(bytes) end it "can write and then read the block-deflated files" do - f = Tempfile.new("raw") + f = ManagedTempfile.new("raw") f.binmode rewind_after(f) do @@ -123,7 +123,7 @@ def stream_with_just_write.write(bytes) end # Perform the zipping - zip_file = Tempfile.new("z") + zip_file = ManagedTempfile.new("z") zip_file.binmode described_class.open(zip_file) do |zip| @@ -147,13 +147,11 @@ def stream_with_just_write.write(bytes) expect(per_filename["compressed-file.bin"].bytesize).to eq(f.size) expect(Digest::SHA1.hexdigest(per_filename["compressed-file.bin"])).to \ eq(Digest::SHA1.hexdigest(f.read)) - - inspect_zip_with_external_tool(zip_file.path) end it "can write and then read an empty directory" do # Perform the zipping - zip_file = Tempfile.new("z") + zip_file = ManagedTempfile.new("z") zip_file.binmode described_class.open(zip_file) do |zip| @@ -172,8 +170,6 @@ def stream_with_just_write.write(bytes) end expect(per_filename["Tunes/"].bytesize).to eq(154) - - inspect_zip_with_external_tool(zip_file.path) end it "can write the data descriptor and updates the last entry as well" do @@ -197,7 +193,7 @@ def stream_with_just_write.write(bytes) end it "archives files which can then be read using the usual means with Rubyzip" do - zip_buf = Tempfile.new("zipp") + zip_buf = ManagedTempfile.new("zipp") zip_buf.binmode output_io = double("IO") @@ -242,17 +238,10 @@ def stream_with_just_write.write(bytes) expect(per_filename["first-file.bin"].unpack("C*")).to eq(raw_file1.unpack("C*")) expect(per_filename["second-file.bin"].unpack("C*")).to eq(raw_file2.unpack("C*")) - - wd = Dir.pwd - Dir.mktmpdir do |td| - Dir.chdir(td) - inspect_zip_with_external_tool(zip_buf.path) - end - Dir.chdir(wd) end it "sets the general-purpose flag for entries with UTF8 names" do - zip_buf = Tempfile.new("zipp") + zip_buf = ManagedTempfile.new("zipp") zip_buf.binmode # Generate a couple of random files @@ -416,8 +405,6 @@ def stream_with_just_write.write(bytes) readback.force_encoding(Encoding::BINARY) expect(readback[0..10]).to eq(File.binread(__dir__ + "/war-and-peace.txt")[0..10]) end - - inspect_zip_with_external_tool(tf.path) end it "can create a valid ZIP archive without any files" do @@ -556,7 +543,7 @@ def stream_with_just_write.write(bytes) end it "supports automatic mode selection using a heuristic" do - zip_file = Tempfile.new + zip_file = ManagedTempfile.new rng = Random.new(42) repeating_string = "many many delicious, compressible words" n_writes = 24000 @@ -609,7 +596,7 @@ def stream_with_just_write.write(bytes) end it "rolls back entries where writes have failed" do - zip_file = Tempfile.new("zipp") + zip_file = ManagedTempfile.new("zipp") described_class.open(zip_file) do |zip| begin zip.write_deflated_file("deflated.txt", modification_time: Time.new(2018, 1, 1)) do |sink|