Sha256: 5de06e35c215593655adb5e670a5e68045847c8c10b31035b36a125f57cbf038

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe Humanize::Bytes::Mega do
  let(:m) { Humanize::Bytes::Mega.new(4.8828125) }

  context "#value" do
    it "should return the value" do
      m.value.should == 4.8828125
    end
  end

  context "#to_b" do
    it "should convert to Byte" do
      m.to_b.class.should be Byte
    end
    it "should convert the value to Bytes" do
      m.to_b.value.should == 5120000
    end
  end

  context "#to_k" do
    it "should convert to Kilo bytes" do
      m.to_k.class.should be Kilo
    end
    it "should convert the value to Kilo bytes" do
      m.to_k.value.should == 5000
    end
  end

  context "#to_m" do
    it "should return self" do
      m.to_m.should be m
    end
  end

  context "#to_g" do
    it "should convert to Giga bytes" do
      m.to_g.class.should be Giga
    end
    it "should convert the value to Giga bytes" do
      m.to_g.value.should == 0.00476837158203125
    end
  end

  context "#to_s" do
    context "when value is a decimal" do
      it "should print a humanized version of the value" do
        m.to_s.should == '4.88 mega bytes'
      end
    end

    context "when value is an integer" do
      it "should print a humanized version of the value" do
        Humanize::Bytes::Mega.new(4).to_s.should == '4 mega bytes'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
humanize-bytes-1.0.0 spec/humanize_bytes/mbyte_spec.rb