From b1a21248d2e71ec4741d1df66d4fd15a5e3b13d1 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 6 Aug 2016 20:37:46 -0400 Subject: add additional tests --- spec/zip_spec.cr | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/zip_spec.cr b/spec/zip_spec.cr index 0ace290..d132c1c 100644 --- a/spec/zip_spec.cr +++ b/spec/zip_spec.cr @@ -1,6 +1,7 @@ require "./spec_helper" TEST_DIR = File.dirname(__FILE__) +TEST_FILE_PATH = File.join(TEST_DIR, "..", "shard.yml") describe Zip do # TODO: Write tests @@ -11,9 +12,35 @@ describe Zip do end describe Zip::Writer do - Zip.write(File.join(TEST_DIR, "test.zip")) do |zip| - zip.add("foo.txt", MemoryIO.new("foo")) - zip.add("bar.txt", "bar") - zip.add_file("shard.yml", File.join(TEST_DIR, "..", "shard.yml")) + it "creates an empty archive" do + Zip.write(File.join(TEST_DIR, "test-empty.zip")) do |zip| + # do nothing + end + end + + it "creates an entry from a String" do + Zip.write(File.join(TEST_DIR, "test-string.zip")) do |zip| + zip.add("bar.txt", "bar") + end + end + + it "creates an entry from a MemoryIO" do + Zip.write(File.join(TEST_DIR, "test-memio.zip")) do |zip| + zip.add("bar.txt", "bar") + end + end + + it "creates an entry from a File" do + Zip.write(File.join(TEST_DIR, "test-file.zip")) do |zip| + zip.add_file("shard.yml", TEST_FILE_PATH) + end + end + + it "creates an archive from a MemoryIO, String, and File" do + Zip.write(File.join(TEST_DIR, "test-many.zip")) do |zip| + zip.add("foo.txt", MemoryIO.new("foo")) + zip.add("bar.txt", "bar") + zip.add_file("shard.yml", TEST_FILE_PATH) + end end end -- cgit v1.2.3