Merge pull request #2180 from Tenzer/cleanup-better-unit-labels

Add 'B' for bytes to cleanup command output
This commit is contained in:
Mike McQuaid 2017-02-26 13:34:32 +00:00 committed by GitHub
commit 765ece86c8
3 changed files with 9 additions and 9 deletions

View File

@ -30,13 +30,13 @@ describe Pathname do
describe "#abv" do
context "when called on a directory" do
it "returns a string with the file count and disk usage" do
expect(dir.abv).to eq("3 files, 1M")
expect(dir.abv).to eq("3 files, 1MB")
end
end
context "when called on a file" do
it "returns the disk usage" do
expect((dir/"a-file").abv).to eq("1M")
expect((dir/"a-file").abv).to eq("1MB")
end
end
end

View File

@ -232,10 +232,10 @@ describe "globally-scoped helper methods" do
specify "#disk_usage_readable" do
expect(disk_usage_readable(1)).to eq("1B")
expect(disk_usage_readable(1000)).to eq("1000B")
expect(disk_usage_readable(1024)).to eq("1K")
expect(disk_usage_readable(1025)).to eq("1K")
expect(disk_usage_readable(4_404_020)).to eq("4.2M")
expect(disk_usage_readable(4_509_715_660)).to eq("4.2G")
expect(disk_usage_readable(1024)).to eq("1KB")
expect(disk_usage_readable(1025)).to eq("1KB")
expect(disk_usage_readable(4_404_020)).to eq("4.2MB")
expect(disk_usage_readable(4_509_715_660)).to eq("4.2GB")
end
describe "#number_readable" do

View File

@ -422,13 +422,13 @@ end
def disk_usage_readable(size_in_bytes)
if size_in_bytes >= 1_073_741_824
size = size_in_bytes.to_f / 1_073_741_824
unit = "G"
unit = "GB"
elsif size_in_bytes >= 1_048_576
size = size_in_bytes.to_f / 1_048_576
unit = "M"
unit = "MB"
elsif size_in_bytes >= 1_024
size = size_in_bytes.to_f / 1_024
unit = "K"
unit = "KB"
else
size = size_in_bytes
unit = "B"