spec/humanize_bytes_spec.rb in humanize-bytes-0.0.2 vs spec/humanize_bytes_spec.rb in humanize-bytes-0.1.0
- old
+ new
@@ -1,29 +1,65 @@
require 'spec_helper'
describe Humanize::Bytes do
describe "#initialize" do
- context "when no unit is specified" do
+ context "when the second parameter is nil" do
it "should return a new Byte instance" do
Humanize::Bytes.initialize(1024).should be_instance_of(Humanize::Bytes::Byte)
end
end
- context "when kilo is specfied as unit" do
+ context "when the second parameter is 'b'" do
it "should return a new Kilo instance" do
+ Humanize::Bytes.initialize(1024, 'b').should be_instance_of(Humanize::Bytes::Byte)
+ end
+ end
+
+ context "when the second parameter is 'k'" do
+ it "should return a new Kilo instance" do
Humanize::Bytes.initialize(1024, 'k').should be_instance_of(Humanize::Bytes::Kilo)
end
end
- context "when mega is specfied as unit" do
+ context "when the second parameter is 'm'" do
it "should return a new Mega instance" do
Humanize::Bytes.initialize(1024, 'm').should be_instance_of(Humanize::Bytes::Mega)
end
end
- context "when giga is specfied as unit" do
+ context "when the second parameter is 'g'" do
it "should return a new Giga instance" do
Humanize::Bytes.initialize(1024, 'g').should be_instance_of(Humanize::Bytes::Giga)
+ end
+ end
+
+ context "when the second parameter is :b" do
+ it "should return a new Kilo instance" do
+ Humanize::Bytes.initialize(1024, :b).should be_instance_of(Humanize::Bytes::Byte)
+ end
+ end
+
+ context "when the second parameter is :k" do
+ it "should return a new Kilo instance" do
+ Humanize::Bytes.initialize(1024, :k).should be_instance_of(Humanize::Bytes::Kilo)
+ end
+ end
+
+ context "when the second parameter is :m" do
+ it "should return a new Mega instance" do
+ Humanize::Bytes.initialize(1024, :m).should be_instance_of(Humanize::Bytes::Mega)
+ end
+ end
+
+ context "when the second parameter is :g" do
+ it "should return a new Giga instance" do
+ Humanize::Bytes.initialize(1024, :g).should be_instance_of(Humanize::Bytes::Giga)
+ end
+ end
+
+ context "when the second parameter is any other thing" do
+ it "should return nil" do
+ Humanize::Bytes.initialize(1024, :thing).should be_nil
end
end
end
end
\ No newline at end of file