diff --git a/colorls.gemspec b/colorls.gemspec index 8bf8d0a..484f7b2 100644 --- a/colorls.gemspec +++ b/colorls.gemspec @@ -72,7 +72,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'diffy', '3.4.2' spec.add_development_dependency 'rake', '~> 13' spec.add_development_dependency 'rdoc', '~> 6.1' - spec.add_development_dependency 'ronn', '~> 0' + spec.add_development_dependency 'ronn-ng', '~> 0' spec.add_development_dependency 'rspec', '~> 3.7' spec.add_development_dependency 'rspec-its', '~> 1.2' spec.add_development_dependency 'rubocop', '~> 1.50.1' diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index f5f7707..2027cda 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -260,7 +260,7 @@ module ColorLS def size_info(filesize) filesize = Filesize.new(filesize) - size = @show_human_readable_size ? filesize.pretty : filesize.to_s + size = @show_human_readable_size ? filesize.pretty(precision: 0) : filesize.to_s('B', precision: 0) size = size.split size = justify_size_info(size) return size.colorize(@colors[:file_large]) if filesize >= 512 * (1024 ** 2) @@ -280,7 +280,7 @@ module ColorLS end def justify_size_info(size) - size_num = size[0][0..-4].rjust(chars_for_size, ' ') + size_num = size[0].rjust(chars_for_size, ' ') size_unit = @show_human_readable_size ? size[1].ljust(3, ' ') : size[1] "#{size_num} #{size_unit}" end diff --git a/spec/color_ls/flags_spec.rb b/spec/color_ls/flags_spec.rb index 746df84..a730b82 100644 --- a/spec/color_ls/flags_spec.rb +++ b/spec/color_ls/flags_spec.rb @@ -65,7 +65,7 @@ RSpec.describe ColorLS::Flags do it 'displays multiple files per line' do allow($stdout).to receive(:tty?).and_return(true) - expect { subject }.not_to output(/(.*\n){4}/).to_stdout + expect { subject }.not_to output(/(.*\n){7}/).to_stdout end it('does not display ./ or ../') { expect { subject }.not_to output(%r(\.{1,2}/)).to_stdout } @@ -103,6 +103,14 @@ RSpec.describe ColorLS::Flags do let(:args) { ['--long', FIXTURES] } it('lists file info') { expect { subject }.to output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout } + + it 'rounds up file size to nearest MiB' do + expect { subject }.to output(/2 MiB[^\n]* 20kb-less-than-2mb\.txt/).to_stdout + end + + it 'rounds down file size to nearest MiB' do + expect { subject }.to output(/1 MiB[^\n]* 20kb-more-than-1mb\.txt/).to_stdout + end end context 'with --long flag for `a.txt`' do @@ -347,7 +355,7 @@ RSpec.describe ColorLS::Flags do let(:args) { ['--report', '--report=long', FIXTURES] } it 'shows a report with recognized and unrecognized files' do - expect { subject }.to output(/Recognized files\s+: 4\n.+Unrecognized files\s+: 3/).to_stdout + expect { subject }.to output(/Recognized files\s+: 6\n.+Unrecognized files\s+: 3/).to_stdout end end diff --git a/spec/fixtures/20kb-less-than-2mb.txt b/spec/fixtures/20kb-less-than-2mb.txt new file mode 100644 index 0000000..d54c570 Binary files /dev/null and b/spec/fixtures/20kb-less-than-2mb.txt differ diff --git a/spec/fixtures/20kb-more-than-1mb.txt b/spec/fixtures/20kb-more-than-1mb.txt new file mode 100644 index 0000000..c9b4e1f Binary files /dev/null and b/spec/fixtures/20kb-more-than-1mb.txt differ