From d80e7203d8ef21b97ec16623738a1bd252d94e3c Mon Sep 17 00:00:00 2001 From: Takumasa Ochi Date: Wed, 28 Jun 2017 11:36:14 +0900 Subject: [PATCH 1/3] Add rubocop dependency and correct settings --- .rubocop.yml | 4 +++- rubyzip.gemspec | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 75dce5fd..2733bcda 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,2 +1,4 @@ inherit_from: - - .rubocop_rubyzip.yml \ No newline at end of file + - .rubocop_rubyzip.yml +AllCops: + TargetRubyVersion: 1.9 diff --git a/rubyzip.gemspec b/rubyzip.gemspec index ccd9ba56..4857e0fb 100644 --- a/rubyzip.gemspec +++ b/rubyzip.gemspec @@ -20,4 +20,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry', '~> 0.10' s.add_development_dependency 'minitest', '~> 5.4' s.add_development_dependency 'coveralls', '~> 0.7' + s.add_development_dependency 'rubocop', '~> 0.49.1' end From 9bfc52b2b7d01f9c1ff49b74d233d6ce6c13d3ed Mon Sep 17 00:00:00 2001 From: Takumasa Ochi Date: Thu, 29 Jun 2017 11:50:04 +0900 Subject: [PATCH 2/3] Disable Style/MutableConstant because existent code relies on it --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 2733bcda..a408fa0d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,3 +2,5 @@ inherit_from: - .rubocop_rubyzip.yml AllCops: TargetRubyVersion: 1.9 +Style/MutableConstant: + Enabled: false # Because some existent code relies on mutable constant From cf91112b57404af217437b20d9414db3b7941538 Mon Sep 17 00:00:00 2001 From: Takumasa Ochi Date: Thu, 29 Jun 2017 11:57:12 +0900 Subject: [PATCH 3/3] Apply automatic correction by rubocop --- lib/zip/central_directory.rb | 6 +- lib/zip/compressor.rb | 3 +- lib/zip/constants.rb | 6 +- lib/zip/crypto/null_encryption.rb | 6 +- lib/zip/decompressor.rb | 2 +- lib/zip/dos_time.rb | 2 +- lib/zip/entry.rb | 34 +++++------ lib/zip/entry_set.rb | 6 +- lib/zip/extra_field.rb | 2 +- lib/zip/extra_field/generic.rb | 2 +- lib/zip/extra_field/zip64_placeholder.rb | 3 +- lib/zip/file.rb | 22 +++---- lib/zip/filesystem.rb | 26 ++++---- lib/zip/inflater.rb | 2 +- lib/zip/input_stream.rb | 11 ++-- lib/zip/ioextras/abstract_input_stream.rb | 2 +- lib/zip/ioextras/abstract_output_stream.rb | 2 +- lib/zip/output_stream.rb | 10 ++-- lib/zip/pass_thru_decompressor.rb | 2 +- rubyzip.gemspec | 3 +- samples/example_recursive.rb | 4 +- samples/gtk_ruby_zip.rb | 2 +- samples/qtzip.rb | 2 +- samples/zipfind.rb | 4 +- test/central_directory_entry_test.rb | 2 +- test/errors_test.rb | 1 + test/file_permissions_test.rb | 26 ++++---- test/file_test.rb | 13 ++-- test/filesystem/dir_iterator_test.rb | 2 +- test/filesystem/directory_test.rb | 12 ++-- test/filesystem/file_mutating_test.rb | 7 +-- test/filesystem/file_nonmutating_test.rb | 62 ++++++++++---------- test/filesystem/file_stat_test.rb | 8 +-- test/gentestfiles.rb | 12 ++-- test/input_stream_test.rb | 12 ++-- test/ioextras/abstract_output_stream_test.rb | 4 +- test/test_helper.rb | 4 +- test/zip64_full_test.rb | 2 +- 38 files changed, 161 insertions(+), 170 deletions(-) diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index cb7e2da7..0b6874ef 100644 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -96,7 +96,7 @@ def read_64_e_o_c_d(buf) #:nodoc: @size_in_bytes = Entry.read_zip_64_long(buf) @cdir_offset = Entry.read_zip_64_long(buf) @zip_64_extensible = buf.slice!(0, buf.bytesize) - raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0 + raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty? end def read_e_o_c_d(buf) #:nodoc: @@ -113,7 +113,7 @@ def read_e_o_c_d(buf) #:nodoc: else buf.read(comment_length) end - raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0 + raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty? end def read_central_directory_entries(io) #:nodoc: @@ -130,7 +130,7 @@ def read_central_directory_entries(io) #:nodoc: def read_from_stream(io) #:nodoc: buf = start_buf(io) - if self.zip64_file?(buf) + if zip64_file?(buf) read_64_e_o_c_d(buf) else read_e_o_c_d(buf) diff --git a/lib/zip/compressor.rb b/lib/zip/compressor.rb index ce2b847f..079c1cb0 100644 --- a/lib/zip/compressor.rb +++ b/lib/zip/compressor.rb @@ -1,7 +1,6 @@ module Zip class Compressor #:nodoc:all - def finish - end + def finish; end end end diff --git a/lib/zip/constants.rb b/lib/zip/constants.rb index 94f8f501..5eb5c1da 100644 --- a/lib/zip/constants.rb +++ b/lib/zip/constants.rb @@ -11,9 +11,9 @@ module Zip VERSION_NEEDED_TO_EXTRACT = 20 VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45 - FILE_TYPE_FILE = 010 - FILE_TYPE_DIR = 004 - FILE_TYPE_SYMLINK = 012 + FILE_TYPE_FILE = 0o10 + FILE_TYPE_DIR = 0o04 + FILE_TYPE_SYMLINK = 0o12 FSTYPE_FAT = 0 FSTYPE_AMIGA = 1 diff --git a/lib/zip/crypto/null_encryption.rb b/lib/zip/crypto/null_encryption.rb index 62d47f0e..a93f707c 100644 --- a/lib/zip/crypto/null_encryption.rb +++ b/lib/zip/crypto/null_encryption.rb @@ -24,8 +24,7 @@ def data_descriptor(_crc32, _compressed_size, _uncomprssed_size) '' end - def reset! - end + def reset!; end end class NullDecrypter < Decrypter @@ -35,8 +34,7 @@ def decrypt(data) data end - def reset!(_header) - end + def reset!(_header); end end end diff --git a/lib/zip/decompressor.rb b/lib/zip/decompressor.rb index cd0fb054..047ed5e7 100644 --- a/lib/zip/decompressor.rb +++ b/lib/zip/decompressor.rb @@ -1,5 +1,5 @@ module Zip - class Decompressor #:nodoc:all + class Decompressor #:nodoc:all CHUNK_SIZE = 32_768 def initialize(input_stream) super() diff --git a/lib/zip/dos_time.rb b/lib/zip/dos_time.rb index fd9353c6..bf0cb7e0 100644 --- a/lib/zip/dos_time.rb +++ b/lib/zip/dos_time.rb @@ -19,7 +19,7 @@ def to_binary_dos_time end def to_binary_dos_date - (day) + + day + (month << 5) + ((year - 1980) << 9) end diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 0aba0eb8..6e1829ae 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -99,7 +99,7 @@ def file_type_is?(type) end # Dynamic checkers - %w(directory file symlink).each do |k| + %w[directory file symlink].each do |k| define_method "#{k}?" do file_type_is?(k.to_sym) end @@ -239,7 +239,7 @@ def read_local_entry(io) #:nodoc:all @name = io.read(@name_length) extra = io.read(@extra_length) - @name.gsub!('\\', '/') + @name.tr!('\\', '/') if extra && extra.bytesize != @extra_length raise ::Zip::Error, 'Truncated local zip entry header' @@ -263,8 +263,8 @@ def pack_local_entry @time.to_binary_dos_time, # @last_mod_time , @time.to_binary_dos_date, # @last_mod_date , @crc, - (zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size, - (zip64 && zip64.original_size) ? 0xFFFFFFFF : @size, + zip64 && zip64.compressed_size ? 0xFFFFFFFF : @compressed_size, + zip64 && zip64.original_size ? 0xFFFFFFFF : @size, name_size, @extra ? @extra.local_size : 0].pack('VvvvvvVVVvv') end @@ -308,7 +308,7 @@ def unpack_c_dir_entry(buf) def set_ftype_from_c_dir_entry @ftype = case @fstype when ::Zip::FSTYPE_UNIX - @unix_perms = (@external_file_attributes >> 16) & 07777 + @unix_perms = (@external_file_attributes >> 16) & 0o7777 case (@external_file_attributes >> 28) when ::Zip::FILE_TYPE_DIR :directory @@ -384,14 +384,14 @@ def get_extra_attributes_from_path(path) # :nodoc: stat = file_stat(path) @unix_uid = stat.uid @unix_gid = stat.gid - @unix_perms = stat.mode & 07777 + @unix_perms = stat.mode & 0o7777 end def set_unix_permissions_on_path(dest_path) # BUG: does not update timestamps into account # ignore setuid/setgid bits by default. honor if @restore_ownership - unix_perms_mask = 01777 - unix_perms_mask = 07777 if @restore_ownership + unix_perms_mask = 0o1777 + unix_perms_mask = 0o7777 if @restore_ownership ::FileUtils.chmod(@unix_perms & unix_perms_mask, dest_path) if @restore_permissions && @unix_perms ::FileUtils.chown(@unix_uid, @unix_gid, dest_path) if @restore_ownership && @unix_uid && @unix_gid && ::Process.egid == 0 # File::utimes() @@ -418,15 +418,15 @@ def pack_c_dir_entry @time.to_binary_dos_time, # @last_mod_time , @time.to_binary_dos_date, # @last_mod_date , @crc, - (zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size, - (zip64 && zip64.original_size) ? 0xFFFFFFFF : @size, + zip64 && zip64.compressed_size ? 0xFFFFFFFF : @compressed_size, + zip64 && zip64.original_size ? 0xFFFFFFFF : @size, name_size, @extra ? @extra.c_dir_size : 0, comment_size, - (zip64 && zip64.disk_start_number) ? 0xFFFF : 0, # disk number start + zip64 && zip64.disk_start_number ? 0xFFFF : 0, # disk number start @internal_file_attributes, # file type (binary=0, text=1) @external_file_attributes, # native filesystem attributes - (zip64 && zip64.relative_header_offset) ? 0xFFFFFFFF : @local_header_offset, + zip64 && zip64.relative_header_offset ? 0xFFFFFFFF : @local_header_offset, @name, @extra, @comment @@ -439,18 +439,18 @@ def write_c_dir_entry(io) #:nodoc:all when ::Zip::FSTYPE_UNIX ft = case @ftype when :file - @unix_perms ||= 0644 + @unix_perms ||= 0o644 ::Zip::FILE_TYPE_FILE when :directory - @unix_perms ||= 0755 + @unix_perms ||= 0o755 ::Zip::FILE_TYPE_DIR when :symlink - @unix_perms ||= 0755 + @unix_perms ||= 0o755 ::Zip::FILE_TYPE_SYMLINK end unless ft.nil? - @external_file_attributes = (ft << 12 | (@unix_perms & 07777)) << 16 + @external_file_attributes = (ft << 12 | (@unix_perms & 0o7777)) << 16 end end @@ -464,7 +464,7 @@ def write_c_dir_entry(io) #:nodoc:all def ==(other) return false unless other.class == self.class # Compares contents of local entry and exposed fields - keys_equal = %w(compression_method crc compressed_size size name extra filepath).all? do |k| + keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k| other.__send__(k.to_sym) == __send__(k.to_sym) end keys_equal && time.dos_equals(other.time) diff --git a/lib/zip/entry_set.rb b/lib/zip/entry_set.rb index 21bfd381..3272b2a4 100644 --- a/lib/zip/entry_set.rb +++ b/lib/zip/entry_set.rb @@ -5,7 +5,7 @@ class EntrySet #:nodoc:all def initialize(an_enumerable = []) super() - @entry_set = {} + @entry_set = {} an_enumerable.each { |o| push(o) } end @@ -33,9 +33,9 @@ def delete(entry) entry if @entry_set.delete(to_key(entry)) end - def each(&block) + def each @entry_set = sorted_entries.dup.each do |_, value| - block.call(value) + yield(value) end end diff --git a/lib/zip/extra_field.rb b/lib/zip/extra_field.rb index 225abeb5..cbc2fa8d 100644 --- a/lib/zip/extra_field.rb +++ b/lib/zip/extra_field.rb @@ -8,7 +8,7 @@ def initialize(binstr = nil) def extra_field_type_exist(binstr, id, len, i) field_name = ID_MAP[id].name - if self.member?(field_name) + if member?(field_name) self[field_name].merge(binstr[i, len + 4]) else field_obj = ID_MAP[id].new(binstr[i, len + 4]) diff --git a/lib/zip/extra_field/generic.rb b/lib/zip/extra_field/generic.rb index 7b60bebb..5931b5c2 100644 --- a/lib/zip/extra_field/generic.rb +++ b/lib/zip/extra_field/generic.rb @@ -1,7 +1,7 @@ module Zip class ExtraField::Generic def self.register_map - if self.const_defined?(:HEADER_ID) + if const_defined?(:HEADER_ID) ::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self end end diff --git a/lib/zip/extra_field/zip64_placeholder.rb b/lib/zip/extra_field/zip64_placeholder.rb index f2573eb4..dfaa56e8 100644 --- a/lib/zip/extra_field/zip64_placeholder.rb +++ b/lib/zip/extra_field/zip64_placeholder.rb @@ -6,8 +6,7 @@ class ExtraField::Zip64Placeholder < ExtraField::Generic HEADER_ID = ['9999'].pack('H*') # this ID is used by other libraries such as .NET's Ionic.zip register_map - def initialize(_binstr = nil) - end + def initialize(_binstr = nil); end def pack_for_local "\x00" * 16 diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 8c5173ba..4bc3edc4 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -69,16 +69,15 @@ def initialize(file_name, create = false, buffer = false, options = {}) @name = file_name @comment = '' @create = create ? true : false # allow any truthy value to mean true - case - when !buffer && ::File.size?(file_name) + if !buffer && ::File.size?(file_name) @create = false @file_permissions = ::File.stat(file_name).mode ::File.open(name, 'rb') do |f| read_from_stream(f) end - when @create + elsif @create @entry_set = EntrySet.new - when ::File.zero?(file_name) + elsif ::File.zero?(file_name) raise Error, "File #{file_name} has zero size. Did you mean to pass the create flag?" else raise Error, "File #{file_name} not found" @@ -151,10 +150,9 @@ def foreach(aZipFileName, &block) end def get_segment_size_for_split(segment_size) - case - when MIN_SEGMENT_SIZE > segment_size + if MIN_SEGMENT_SIZE > segment_size MIN_SEGMENT_SIZE - when MAX_SEGMENT_SIZE < segment_size + elsif MAX_SEGMENT_SIZE < segment_size MAX_SEGMENT_SIZE else segment_size @@ -162,8 +160,10 @@ def get_segment_size_for_split(segment_size) end def get_partial_zip_file_name(zip_file_name, partial_zip_file_name) - partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/, - partial_zip_file_name + ::File.extname(zip_file_name)) unless partial_zip_file_name.nil? + unless partial_zip_file_name.nil? + partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/, + partial_zip_file_name + ::File.extname(zip_file_name)) + end partial_zip_file_name ||= zip_file_name partial_zip_file_name end @@ -237,7 +237,7 @@ def get_input_stream(entry, &aProc) # specified. If a block is passed the stream object is passed to the block and # the stream is automatically closed afterwards just as with ruby's builtin # File.open method. - def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc) + def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc) new_entry = if entry.kind_of?(Entry) entry @@ -366,7 +366,7 @@ def get_entry(entry) end # Creates a directory - def mkdir(entryName, permissionInt = 0755) + def mkdir(entryName, permissionInt = 0o755) raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName) entryName = entryName.dup.to_s entryName << '/' unless entryName.end_with?('/') diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index c77cdf4d..fb64325b 100644 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -142,9 +142,9 @@ def rdev_minor def ftype if file? - return 'file' + 'file' elsif directory? - return 'directory' + 'directory' else raise StandardError, 'Unknown file type' end @@ -198,30 +198,30 @@ def exists?(fileName) alias grpowned? exists? def readable?(fileName) - unix_mode_cmp(fileName, 0444) + unix_mode_cmp(fileName, 0o444) end alias readable_real? readable? def writable?(fileName) - unix_mode_cmp(fileName, 0222) + unix_mode_cmp(fileName, 0o222) end alias writable_real? writable? def executable?(fileName) - unix_mode_cmp(fileName, 0111) + unix_mode_cmp(fileName, 0o111) end alias executable_real? executable? def setuid?(fileName) - unix_mode_cmp(fileName, 04000) + unix_mode_cmp(fileName, 0o4000) end def setgid?(fileName) - unix_mode_cmp(fileName, 02000) + unix_mode_cmp(fileName, 0o2000) end def sticky?(fileName) - unix_mode_cmp(fileName, 01000) + unix_mode_cmp(fileName, 0o1000) end def umask(*args) @@ -237,8 +237,8 @@ def directory?(fileName) expand_path(fileName) == '/' || (!entry.nil? && entry.directory?) end - def open(fileName, openMode = 'r', permissionInt = 0644, &block) - openMode.gsub!('b', '') # ignore b option + def open(fileName, openMode = 'r', permissionInt = 0o644, &block) + openMode.delete!('b') # ignore b option case openMode when 'r' @mappedZip.get_input_stream(fileName, &block) @@ -260,7 +260,7 @@ def size(fileName) # Returns nil for not found and nil for directories def size?(fileName) entry = @mappedZip.find_entry(fileName) - (entry.nil? || entry.directory?) ? nil : entry.size + entry.nil? || entry.directory? ? nil : entry.size end def chown(ownerInt, groupInt, *filenames) @@ -498,7 +498,7 @@ def delete(entryName) alias rmdir delete alias unlink delete - def mkdir(entryName, permissionInt = 0755) + def mkdir(entryName, permissionInt = 0o755) @mappedZip.mkdir(entryName, permissionInt) end @@ -586,7 +586,7 @@ def rename(fileName, newName, &continueOnExistsProc) &continueOnExistsProc) end - def mkdir(fileName, permissionInt = 0755) + def mkdir(fileName, permissionInt = 0o755) @zipFile.mkdir(expand_to_entry(fileName), permissionInt) end diff --git a/lib/zip/inflater.rb b/lib/zip/inflater.rb index 0e2b97e1..ef952f07 100644 --- a/lib/zip/inflater.rb +++ b/lib/zip/inflater.rb @@ -5,7 +5,7 @@ def initialize(input_stream, decrypter = NullDecrypter.new) @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS) @output_buffer = '' @has_returned_empty_string = false - @decrypter = decrypter + @decrypter = decrypter end def sysread(number_of_bytes = nil, buf = '') diff --git a/lib/zip/input_stream.rb b/lib/zip/input_stream.rb index f8e78868..4c861c56 100644 --- a/lib/zip/input_stream.rb +++ b/lib/zip/input_stream.rb @@ -129,23 +129,22 @@ def open_entry end if @current_entry && @current_entry.gp_flags & 8 == 8 && @current_entry.crc == 0 \ && @current_entry.compressed_size == 0 \ - && @current_entry.size == 0 && !@internal + && @current_entry.empty? && !@internal raise GPFBit3Error, 'General purpose flag Bit 3 is set so not possible to get proper info from local header.' \ 'Please use ::Zip::File instead of ::Zip::InputStream' end - @decompressor = get_decompressor + @decompressor = get_decompressor flush @current_entry end def get_decompressor - case - when @current_entry.nil? + if @current_entry.nil? ::Zip::NullDecompressor - when @current_entry.compression_method == ::Zip::Entry::STORED + elsif @current_entry.compression_method == ::Zip::Entry::STORED ::Zip::PassThruDecompressor.new(@archive_io, @current_entry.size) - when @current_entry.compression_method == ::Zip::Entry::DEFLATED + elsif @current_entry.compression_method == ::Zip::Entry::DEFLATED header = @archive_io.read(@decrypter.header_bytesize) @decrypter.reset!(header) ::Zip::Inflater.new(@archive_io, @decrypter) diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index 5db051e1..7b7fd61d 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -33,7 +33,7 @@ def read(number_of_bytes = nil, buf = '') sysread(number_of_bytes, buf) end - if tbuf.nil? || tbuf.length == 0 + if tbuf.nil? || tbuf.empty? return nil if number_of_bytes return '' end diff --git a/lib/zip/ioextras/abstract_output_stream.rb b/lib/zip/ioextras/abstract_output_stream.rb index c1246f97..69d0cc7c 100644 --- a/lib/zip/ioextras/abstract_output_stream.rb +++ b/lib/zip/ioextras/abstract_output_stream.rb @@ -15,7 +15,7 @@ def print(*params) end def printf(a_format_string, *params) - self << sprintf(a_format_string, *params) + self << format(a_format_string, *params) end def putc(an_object) diff --git a/lib/zip/output_stream.rb b/lib/zip/output_stream.rb index 693678be..d9bbc4df 100644 --- a/lib/zip/output_stream.rb +++ b/lib/zip/output_stream.rb @@ -87,11 +87,11 @@ def close_buffer # +entry+ can be a ZipEntry object or a string. def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression) raise Error, 'zip stream is closed' if @closed - if entry_name.kind_of?(Entry) - new_entry = entry_name - else - new_entry = Entry.new(@file_name, entry_name.to_s) - end + new_entry = if entry_name.kind_of?(Entry) + entry_name + else + Entry.new(@file_name, entry_name.to_s) + end new_entry.comment = comment unless comment.nil? unless extra.nil? new_entry.extra = extra.is_a?(ExtraField) ? extra : ExtraField.new(extra.to_s) diff --git a/lib/zip/pass_thru_decompressor.rb b/lib/zip/pass_thru_decompressor.rb index ca30f5d4..485462c5 100644 --- a/lib/zip/pass_thru_decompressor.rb +++ b/lib/zip/pass_thru_decompressor.rb @@ -1,5 +1,5 @@ module Zip - class PassThruDecompressor < Decompressor #:nodoc:all + class PassThruDecompressor < Decompressor #:nodoc:all def initialize(input_stream, chars_to_read) super(input_stream) @chars_to_read = chars_to_read diff --git a/rubyzip.gemspec b/rubyzip.gemspec index 4857e0fb..4ca36c2d 100644 --- a/rubyzip.gemspec +++ b/rubyzip.gemspec @@ -1,4 +1,5 @@ #-*- encoding: utf-8 -*- + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'zip/version' @@ -11,7 +12,7 @@ Gem::Specification.new do |s| s.homepage = 'http://github.com/rubyzip/rubyzip' s.platform = Gem::Platform::RUBY s.summary = 'rubyzip is a ruby module for reading and writing zip files' - s.files = Dir.glob('{samples,lib}/**/*.rb') + %w(README.md TODO Rakefile) + s.files = Dir.glob('{samples,lib}/**/*.rb') + %w[README.md TODO Rakefile] s.test_files = Dir.glob('test/**/*') s.require_paths = ['lib'] s.license = 'BSD 2-Clause' diff --git a/samples/example_recursive.rb b/samples/example_recursive.rb index c0680b72..ea4c082b 100644 --- a/samples/example_recursive.rb +++ b/samples/example_recursive.rb @@ -19,7 +19,7 @@ def initialize(input_dir, output_file) # Zip the input directory. def write - entries = Dir.entries(@input_dir) - %w(. ..) + entries = Dir.entries(@input_dir) - %w[. ..] ::Zip::File.open(@output_file, ::Zip::File::CREATE) do |io| write_entries entries, '', io @@ -45,7 +45,7 @@ def write_entries(entries, path, io) def recursively_deflate_directory(disk_file_path, io, zip_file_path) io.mkdir zip_file_path - subdir = Dir.entries(disk_file_path) - %w(. ..) + subdir = Dir.entries(disk_file_path) - %w[. ..] write_entries subdir, zip_file_path, io end diff --git a/samples/gtk_ruby_zip.rb b/samples/gtk_ruby_zip.rb index 2b5a2883..62f005a5 100755 --- a/samples/gtk_ruby_zip.rb +++ b/samples/gtk_ruby_zip.rb @@ -31,7 +31,7 @@ def initialize sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) box.pack_start(sw, true, true, 0) - @clist = Gtk::CList.new(%w(Name Size Compression)) + @clist = Gtk::CList.new(%w[Name Size Compression]) @clist.set_selection_mode(Gtk::SELECTION_BROWSE) @clist.set_column_width(0, 120) @clist.set_column_width(1, 120) diff --git a/samples/qtzip.rb b/samples/qtzip.rb index c47fc97c..1d450a78 100755 --- a/samples/qtzip.rb +++ b/samples/qtzip.rb @@ -65,7 +65,7 @@ def extract_files end puts "selected_items.size = #{selected_items.size}" puts "unselected_items.size = #{unselected_items.size}" - items = selected_items.size > 0 ? selected_items : unselected_items + items = !selected_items.empty? ? selected_items : unselected_items puts "items.size = #{items.size}" d = Qt::FileDialog.get_existing_directory(nil, self) diff --git a/samples/zipfind.rb b/samples/zipfind.rb index fa2aa4e6..400e0a69 100755 --- a/samples/zipfind.rb +++ b/samples/zipfind.rb @@ -31,7 +31,7 @@ def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i) end end -if __FILE__ == $0 +if $0 == __FILE__ module ZipFindConsoleRunner PATH_ARG_INDEX = 0 FILENAME_PATTERN_ARG_INDEX = 1 @@ -47,7 +47,7 @@ def self.run(args) end def self.check_args(args) - if (args.size != 3) + if args.size != 3 usage exit end diff --git a/test/central_directory_entry_test.rb b/test/central_directory_entry_test.rb index 35a16cde..fa0d8065 100644 --- a/test/central_directory_entry_test.rb +++ b/test/central_directory_entry_test.rb @@ -2,7 +2,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test def test_read_from_stream - File.open('test/data/testDirectory.bin', 'rb') do |file| + File.open('test/data/testDirectory.bin', 'rb') do |file| entry = ::Zip::Entry.read_c_dir_entry(file) assert_equal('longAscii.txt', entry.name) diff --git a/test/errors_test.rb b/test/errors_test.rb index a65a3afa..2c6adb2f 100644 --- a/test/errors_test.rb +++ b/test/errors_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 + require 'test_helper' class ErrorsTest < MiniTest::Test diff --git a/test/file_permissions_test.rb b/test/file_permissions_test.rb index fd666b88..4e4573a4 100644 --- a/test/file_permissions_test.rb +++ b/test/file_permissions_test.rb @@ -1,9 +1,8 @@ require 'test_helper' class FilePermissionsTest < MiniTest::Test - - ZIPNAME = File.join(File.dirname(__FILE__), "umask.zip") - FILENAME = File.join(File.dirname(__FILE__), "umask.txt") + ZIPNAME = File.join(File.dirname(__FILE__), 'umask.zip') + FILENAME = File.join(File.dirname(__FILE__), 'umask.txt') def teardown ::File.unlink(ZIPNAME) @@ -16,7 +15,7 @@ def test_current_umask end def test_umask_000 - set_umask(0000) do + set_umask(0o000) do create_files end @@ -24,7 +23,7 @@ def test_umask_000 end def test_umask_066 - set_umask(0066) do + set_umask(0o066) do create_files end @@ -32,7 +31,7 @@ def test_umask_066 end def test_umask_027 - set_umask(0027) do + set_umask(0o027) do create_files end @@ -48,7 +47,7 @@ def assert_matching_permissions(expected_file, actual_file) def create_files ::Zip::File.open(ZIPNAME, ::Zip::File::CREATE) do |zip| - zip.comment = "test" + zip.comment = 'test' end ::File.open(FILENAME, 'w') do |file| @@ -57,13 +56,10 @@ def create_files end # If anything goes wrong, make sure the umask is restored. - def set_umask(umask, &block) - begin - saved_umask = ::File.umask(umask) - yield - ensure - ::File.umask(saved_umask) - end + def set_umask(umask) + saved_umask = ::File.umask(umask) + yield + ensure + ::File.umask(saved_umask) end - end diff --git a/test/file_test.rb b/test/file_test.rb index a6d187ea..73f60af5 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -142,15 +142,15 @@ def test_add def test_recover_permissions_after_add_files_to_archive srcZip = TEST_ZIP.zip_name - ::File.chmod(0664, srcZip) + ::File.chmod(0o664, srcZip) srcFile = 'test/data/file2.txt' entryName = 'newEntryName.rb' - assert_equal(::File.stat(srcZip).mode, 0100664) + assert_equal(::File.stat(srcZip).mode, 0o100664) assert(::File.exist?(srcZip)) zf = ::Zip::File.new(srcZip, ::Zip::File::CREATE) zf.add(entryName, srcFile) zf.close - assert_equal(::File.stat(srcZip).mode, 0100664) + assert_equal(::File.stat(srcZip).mode, 0o100664) end def test_add_existing_entry_name @@ -234,7 +234,7 @@ def test_rename_with_each zf.mkdir('test') arr << 'test/' arr_renamed << 'Ztest/' - %w(a b c d).each do |f| + %w[a b c d].each do |f| zf.get_output_stream("test/#{f}") { |file| file.puts 'aaaa' } arr << "test/#{f}" arr_renamed << "Ztest/#{f}" @@ -329,7 +329,7 @@ def test_replace def test_replace_non_entry entryToReplace = 'nonExistingEntryname' - ::Zip::File.open(TEST_ZIP.zip_name) do |zf| + ::Zip::File.open(TEST_ZIP.zip_name) do |zf| assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, 'test/data/file2.txt') } end end @@ -434,7 +434,6 @@ def test_compound1 filename_to_remove = originalEntries.map(&:to_s).find { |name| name.match('longBinary') } zf.remove(filename_to_remove) assert_not_contains(zf, filename_to_remove) - ensure zf.close end @@ -558,7 +557,7 @@ def test_odd_extra_field entry_count = 0 File.open 'test/data/oddExtraField.zip', 'rb' do |zip_io| Zip::File.open_buffer zip_io.read do |zip| - zip.each do |zip_entry| + zip.each do |_zip_entry| entry_count += 1 end end diff --git a/test/filesystem/dir_iterator_test.rb b/test/filesystem/dir_iterator_test.rb index c2cf00ac..8d12ce27 100644 --- a/test/filesystem/dir_iterator_test.rb +++ b/test/filesystem/dir_iterator_test.rb @@ -2,7 +2,7 @@ require 'zip/filesystem' class ZipFsDirIteratorTest < MiniTest::Test - FILENAME_ARRAY = %w(f1 f2 f3 f4 f5 f6) + FILENAME_ARRAY = %w[f1 f2 f3 f4 f5 f6] def setup @dirIt = ::Zip::FileSystem::ZipFsDirIterator.new(FILENAME_ARRAY) diff --git a/test/filesystem/directory_test.rb b/test/filesystem/directory_test.rb index d6c029f3..ec0a7371 100644 --- a/test/filesystem/directory_test.rb +++ b/test/filesystem/directory_test.rb @@ -51,10 +51,10 @@ def test_pwd_chdir_entries zf.dir.chdir 'file1' end - assert_equal(%w(dir1 dir2 file1).sort, zf.dir.entries('.').sort) + assert_equal(%w[dir1 dir2 file1].sort, zf.dir.entries('.').sort) zf.dir.chdir 'dir1' assert_equal('/dir1', zf.dir.pwd) - assert_equal(%w(dir11 file11 file12), zf.dir.entries('.').sort) + assert_equal(%w[dir11 file11 file12], zf.dir.entries('.').sort) zf.dir.chdir '../dir2/dir21' assert_equal('/dir2/dir21', zf.dir.pwd) @@ -77,11 +77,11 @@ def test_foreach entries = [] zf.dir.foreach('.') { |e| entries << e } - assert_equal(%w(dir1 dir2 file1).sort, entries.sort) + assert_equal(%w[dir1 dir2 file1].sort, entries.sort) entries = [] zf.dir.foreach('dir1') { |e| entries << e } - assert_equal(%w(dir11 file11 file12), entries.sort) + assert_equal(%w[dir11 file11 file12], entries.sort) end end @@ -110,11 +110,11 @@ def test_open_new end d = zf.dir.new('.') - assert_equal(%w(file1 dir1 dir2).sort, d.entries.sort) + assert_equal(%w[file1 dir1 dir2].sort, d.entries.sort) d.close zf.dir.open('dir1') do |dir| - assert_equal(%w(dir11 file11 file12).sort, dir.entries.sort) + assert_equal(%w[dir11 file11 file12].sort, dir.entries.sort) end end end diff --git a/test/filesystem/file_mutating_test.rb b/test/filesystem/file_mutating_test.rb index e398060a..ccba6e3d 100644 --- a/test/filesystem/file_mutating_test.rb +++ b/test/filesystem/file_mutating_test.rb @@ -7,8 +7,7 @@ def setup FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP) end - def teardown - end + def teardown; end def test_delete do_test_delete_or_unlink(:delete) @@ -51,11 +50,11 @@ def test_rename def test_chmod ::Zip::File.open(TEST_ZIP) do |zf| - zf.file.chmod(0765, 'file1') + zf.file.chmod(0o765, 'file1') end ::Zip::File.open(TEST_ZIP) do |zf| - assert_equal(0100765, zf.file.stat('file1').mode) + assert_equal(0o100765, zf.file.stat('file1').mode) end end diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index e8242258..62486666 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -14,11 +14,11 @@ def teardown def test_umask assert_equal(::File.umask, @zip_file.file.umask) - @zip_file.file.umask(0006) + @zip_file.file.umask(0o006) end def test_exists? - assert(! @zip_file.file.exists?('notAFile')) + assert(!@zip_file.file.exists?('notAFile')) assert(@zip_file.file.exists?('file1')) assert(@zip_file.file.exists?('dir1')) assert(@zip_file.file.exists?('dir1/')) @@ -114,13 +114,13 @@ def test_size? def test_file? assert(@zip_file.file.file?('file1')) assert(@zip_file.file.file?('dir2/file21')) - assert(! @zip_file.file.file?('dir1')) - assert(! @zip_file.file.file?('dir1/dir11')) + assert(!@zip_file.file.file?('dir1')) + assert(!@zip_file.file.file?('dir1/dir11')) assert(@zip_file.file.stat('file1').file?) assert(@zip_file.file.stat('dir2/file21').file?) - assert(! @zip_file.file.stat('dir1').file?) - assert(! @zip_file.file.stat('dir1/dir11').file?) + assert(!@zip_file.file.stat('dir1').file?) + assert(!@zip_file.file.stat('dir1/dir11').file?) end include ExtraAssertions @@ -160,15 +160,15 @@ def test_utime end def assert_always_false(operation) - assert(! @zip_file.file.send(operation, 'noSuchFile')) - assert(! @zip_file.file.send(operation, 'file1')) - assert(! @zip_file.file.send(operation, 'dir1')) - assert(! @zip_file.file.stat('file1').send(operation)) - assert(! @zip_file.file.stat('dir1').send(operation)) + assert(!@zip_file.file.send(operation, 'noSuchFile')) + assert(!@zip_file.file.send(operation, 'file1')) + assert(!@zip_file.file.send(operation, 'dir1')) + assert(!@zip_file.file.stat('file1').send(operation)) + assert(!@zip_file.file.stat('dir1').send(operation)) end def assert_true_if_entry_exists(operation) - assert(! @zip_file.file.send(operation, 'noSuchFile')) + assert(!@zip_file.file.send(operation, 'noSuchFile')) assert(@zip_file.file.send(operation, 'file1')) assert(@zip_file.file.send(operation, 'dir1')) assert(@zip_file.file.stat('file1').send(operation)) @@ -221,15 +221,15 @@ def test_link end def test_directory? - assert(! @zip_file.file.directory?('notAFile')) - assert(! @zip_file.file.directory?('file1')) - assert(! @zip_file.file.directory?('dir1/file11')) + assert(!@zip_file.file.directory?('notAFile')) + assert(!@zip_file.file.directory?('file1')) + assert(!@zip_file.file.directory?('dir1/file11')) assert(@zip_file.file.directory?('dir1')) assert(@zip_file.file.directory?('dir1/')) assert(@zip_file.file.directory?('dir2/dir21')) - assert(! @zip_file.file.stat('file1').directory?) - assert(! @zip_file.file.stat('dir1/file11').directory?) + assert(!@zip_file.file.stat('file1').directory?) + assert(!@zip_file.file.stat('dir1/file11').directory?) assert(@zip_file.file.stat('dir1').directory?) assert(@zip_file.file.stat('dir1/').directory?) assert(@zip_file.file.stat('dir2/dir21').directory?) @@ -243,8 +243,8 @@ def test_chown end def test_zero? - assert(! @zip_file.file.zero?('notAFile')) - assert(! @zip_file.file.zero?('file1')) + assert(!@zip_file.file.zero?('notAFile')) + assert(!@zip_file.file.zero?('file1')) assert(@zip_file.file.zero?('dir1')) blockCalled = false ::Zip::File.open('test/data/generated/5entry.zip') do |zf| @@ -253,7 +253,7 @@ def test_zero? end assert(blockCalled) - assert(! @zip_file.file.stat('file1').zero?) + assert(!@zip_file.file.stat('file1').zero?) assert(@zip_file.file.stat('dir1').zero?) blockCalled = false ::Zip::File.open('test/data/generated/5entry.zip') do |zf| @@ -309,7 +309,7 @@ def test_ntfs_time end def test_readable? - assert(! @zip_file.file.readable?('noSuchFile')) + assert(!@zip_file.file.readable?('noSuchFile')) assert(@zip_file.file.readable?('file1')) assert(@zip_file.file.readable?('dir1')) assert(@zip_file.file.stat('file1').readable?) @@ -317,7 +317,7 @@ def test_readable? end def test_readable_real? - assert(! @zip_file.file.readable_real?('noSuchFile')) + assert(!@zip_file.file.readable_real?('noSuchFile')) assert(@zip_file.file.readable_real?('file1')) assert(@zip_file.file.readable_real?('dir1')) assert(@zip_file.file.stat('file1').readable_real?) @@ -325,7 +325,7 @@ def test_readable_real? end def test_writable? - assert(! @zip_file.file.writable?('noSuchFile')) + assert(!@zip_file.file.writable?('noSuchFile')) assert(@zip_file.file.writable?('file1')) assert(@zip_file.file.writable?('dir1')) assert(@zip_file.file.stat('file1').writable?) @@ -333,7 +333,7 @@ def test_writable? end def test_writable_real? - assert(! @zip_file.file.writable_real?('noSuchFile')) + assert(!@zip_file.file.writable_real?('noSuchFile')) assert(@zip_file.file.writable_real?('file1')) assert(@zip_file.file.writable_real?('dir1')) assert(@zip_file.file.stat('file1').writable_real?) @@ -341,18 +341,18 @@ def test_writable_real? end def test_executable? - assert(! @zip_file.file.executable?('noSuchFile')) - assert(! @zip_file.file.executable?('file1')) + assert(!@zip_file.file.executable?('noSuchFile')) + assert(!@zip_file.file.executable?('file1')) assert(@zip_file.file.executable?('dir1')) - assert(! @zip_file.file.stat('file1').executable?) + assert(!@zip_file.file.stat('file1').executable?) assert(@zip_file.file.stat('dir1').executable?) end def test_executable_real? - assert(! @zip_file.file.executable_real?('noSuchFile')) - assert(! @zip_file.file.executable_real?('file1')) + assert(!@zip_file.file.executable_real?('noSuchFile')) + assert(!@zip_file.file.executable_real?('file1')) assert(@zip_file.file.executable_real?('dir1')) - assert(! @zip_file.file.stat('file1').executable_real?) + assert(!@zip_file.file.stat('file1').executable_real?) assert(@zip_file.file.stat('dir1').executable_real?) end @@ -455,7 +455,7 @@ def test_glob zf.glob('**/foo.txt') do |match| results << "<#{match.class.name}: #{match}>" end - assert((!results.empty?), 'block not run, or run out of context') + assert(!results.empty?, 'block not run, or run out of context') assert_equal 2, results.size assert_operator results, :include?, '' assert_operator results, :include?, '' diff --git a/test/filesystem/file_stat_test.rb b/test/filesystem/file_stat_test.rb index 51e60d9c..05d7fff8 100644 --- a/test/filesystem/file_stat_test.rb +++ b/test/filesystem/file_stat_test.rb @@ -32,10 +32,10 @@ def test_ftype end def test_mode - assert_equal(0600, @zip_file.file.stat('file1').mode & 0777) - assert_equal(0600, @zip_file.file.stat('file1').mode & 0777) - assert_equal(0755, @zip_file.file.stat('dir1').mode & 0777) - assert_equal(0755, @zip_file.file.stat('dir1').mode & 0777) + assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777) + assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777) + assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777) + assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777) end def test_dev diff --git a/test/gentestfiles.rb b/test/gentestfiles.rb index 88ffd385..a8a2126b 100755 --- a/test/gentestfiles.rb +++ b/test/gentestfiles.rb @@ -76,7 +76,7 @@ def self.create_test_zips File.open('test/data/generated/empty.txt', 'w') {} File.open('test/data/generated/empty_chmod640.txt', 'w') {} - ::File.chmod(0640, 'test/data/generated/empty_chmod640.txt') + ::File.chmod(0o640, 'test/data/generated/empty_chmod640.txt') File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' } ziptestTxt = '' @@ -112,15 +112,15 @@ def self.create_test_zips # http://stahlworks.com/dev/index.php?tool=zipunzip # that works with the above code raise $!.to_s + - "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \ - "to create test data. If you don't have it you can download\n" \ - 'the necessary test files at http://sf.net/projects/rubyzip.' + "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \ + "to create test data. If you don't have it you can download\n" \ + 'the necessary test files at http://sf.net/projects/rubyzip.' end TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', []) - TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w(test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin), + TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w[test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin], 'my zip comment') - TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w(test/data/file1.txt)) + TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w[test/data/file1.txt]) TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt', TestFiles::EMPTY_TEST_DIR]) end diff --git a/test/input_stream_test.rb b/test/input_stream_test.rb index 3a31684d..773ee6b5 100644 --- a/test/input_stream_test.rb +++ b/test/input_stream_test.rb @@ -70,7 +70,7 @@ def test_incomplete_reads entry = zis.get_next_entry # longAscii.txt assert_equal(false, zis.eof?) assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name) - assert zis.gets.length > 0 + assert !zis.gets.empty? assert_equal(false, zis.eof?) entry = zis.get_next_entry # empty.txt assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name) @@ -84,10 +84,10 @@ def test_incomplete_reads assert_equal(true, zis.eof?) entry = zis.get_next_entry # short.txt assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name) - assert zis.gets.length > 0 + assert !zis.gets.empty? entry = zis.get_next_entry # longBinary.bin assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name) - assert zis.gets.length > 0 + assert !zis.gets.empty? end end @@ -97,7 +97,7 @@ def test_incomplete_reads_from_string_io entry = zis.get_next_entry # longAscii.txt assert_equal(false, zis.eof?) assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name) - assert zis.gets.length > 0 + assert !zis.gets.empty? assert_equal(false, zis.eof?) entry = zis.get_next_entry # empty.txt assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name) @@ -111,10 +111,10 @@ def test_incomplete_reads_from_string_io assert_equal(true, zis.eof?) entry = zis.get_next_entry # short.txt assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name) - assert zis.gets.length > 0 + assert !zis.gets.empty? entry = zis.get_next_entry # longBinary.bin assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name) - assert zis.gets.length > 0 + assert !zis.gets.empty? end end diff --git a/test/ioextras/abstract_output_stream_test.rb b/test/ioextras/abstract_output_stream_test.rb index 3c2cefa0..3077db43 100644 --- a/test/ioextras/abstract_output_stream_test.rb +++ b/test/ioextras/abstract_output_stream_test.rb @@ -92,11 +92,11 @@ def test_puts assert_equal("hello\nworld\n", @output_stream.buffer) @output_stream.buffer = '' - @output_stream.puts(["hello\n", "world\n"]) + @output_stream.puts(%W[hello\n world\n]) assert_equal("hello\nworld\n", @output_stream.buffer) @output_stream.buffer = '' - @output_stream.puts(["hello\n", "world\n"], 'bingo') + @output_stream.puts(%W[hello\n world\n], 'bingo') assert_equal("hello\nworld\nbingo\n", @output_stream.buffer) @output_stream.buffer = '' diff --git a/test/test_helper.rb b/test/test_helper.rb index c7cbfb95..ddeba58b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -103,7 +103,7 @@ def assert_entry_contents_for_stream(filename, zis, entryName) File.open(filename, 'rb') do |file| expected = file.read actual = zis.read - if (expected != actual) + if expected != actual if (expected && actual) && (expected.length > 400 || actual.length > 400) zipEntryFilename = entryName + '.zipEntry' File.open(zipEntryFilename, 'wb') { |entryfile| entryfile << actual } @@ -118,7 +118,7 @@ def assert_entry_contents_for_stream(filename, zis, entryName) def self.assert_contents(filename, aString) fileContents = '' File.open(filename, 'rb') { |f| fileContents = f.read } - if (fileContents != aString) + if fileContents != aString if fileContents.length > 400 || aString.length > 400 stringFile = filename + '.other' File.open(stringFile, 'wb') { |f| f << aString } diff --git a/test/zip64_full_test.rb b/test/zip64_full_test.rb index d7fccbb4..464388dc 100644 --- a/test/zip64_full_test.rb +++ b/test/zip64_full_test.rb @@ -36,7 +36,7 @@ def test_large_zip_file end ::Zip::File.open(test_filename) do |zf| - assert_equal %w(first_file.txt huge_file last_file.txt), zf.entries.map(&:name) + assert_equal %w[first_file.txt huge_file last_file.txt], zf.entries.map(&:name) assert_equal first_text, zf.read('first_file.txt') assert_equal last_text, zf.read('last_file.txt') end