test/conversions_test.rb in version_compare-0.0.1 vs test/conversions_test.rb in version_compare-0.0.2

- old
+ new

@@ -1,83 +1,64 @@ require 'test_helper' describe Conversions do describe "conversion function" do it "works on integers" do - assert { Version(1).class == Version } + Version(1).class.must_equal Version end it "works on floats" do - assert { Version(1.2).class == Version } + Version(1.2).class.must_equal Version end it "works on strings" do - assert { Version("1.2.3.4").class == Version } + Version("1.2.3.4").class.must_equal Version end it "works on arrays" do - assert { Version([1, 2, 3, 4]).instance_of?(Version) } - assert { Version([1, 2, 3, 4]) == Version("1.2.3.4") } - assert { Version(["1", "2", "3", "4"]) == Version("1.2.3.4") } + Version([1, 2, 3, 4]).must_be_instance_of Version + Version([1, 2, 3, 4]).must_equal Version("1.2.3.4") + Version(["1", "2", "3", "4"]).must_equal Version("1.2.3.4") end it "works on Versions" do - assert { Version(Version(1.2)).instance_of?(Version) } - assert { Version(Version(1.2)) == Version(1.2) } + Version(Version(1.2)).must_be_instance_of Version + Version(Version(1.2)).must_equal Version(1.2) end end describe "explicit conversions" do describe "#to_s" do it "returns string regardless of input" do - assert { Version(1).to_s == "1" } - assert { Version(1.2).to_s == "1.2" } - assert { Version("1.2.3").to_s == "1.2.3" } + Version(1).to_s.must_equal "1" + Version(1.2).to_s.must_equal "1.2" + Version("1.2.3").to_s.must_equal "1.2.3" end end - describe "#to_f" do - it "returns float when major only" do - assert { Version(1).to_f == 1.0 } - end - - it "returns float when major and minor" do - assert { Version(1.0).to_f == 1.0 } - assert { Version(1.2).to_f == 1.2 } - end - - it "returns truncated float when more than just major and minor" do - assert { Version("1.0.0").to_f == 1.0 } - assert { Version("1.1.9").to_f == 1.1 } - assert { Version("1.0.0.0").to_f == 1.0 } - assert { Version("1.1.9.9").to_f == 1.1 } - end - end - describe "#to_a" do it "returns an array of integers" do - assert { Version(1).to_a == [1] } - assert { Version(1.0).to_a == [1, 0] } - assert { Version("1.2.3").to_a == [1, 2, 3] } - assert { Version("1.2.3.4").to_a == [1, 2, 3, 4] } - assert { Version(["1", "2", "3", "4"]).to_a == [1, 2, 3, 4] } + Version(1).to_a.must_equal [1] + Version(1.0).to_a.must_equal [1, 0] + Version("1.2.3").to_a.must_equal [1, 2, 3] + Version("1.2.3.4").to_a.must_equal [1, 2, 3, 4] + Version(["1", "2", "3", "4"]).to_a.must_equal [1, 2, 3, 4] end end end describe "implicit conversions" do - describe "string concatination" do - it "concatinates" do - assert { ("version: " + Version("1.2.3.4")) == "version: 1.2.3.4" } + describe "string concatenation" do + it "concatenates" do + ("version: " + Version("1.2.3.4")).must_equal "version: 1.2.3.4" end end describe "CustomObjects" do describe "without #to_version" do it "raises TypeError when attempting to convert custom objects that don't implement #to_version" do - assert { rescuing { Version(Object.new) }.instance_of?(TypeError) } - deny { rescuing { Version.new(Object.new) }.is_a?(StandardError) } + -> { Version(Object.new) }.must_raise TypeError end end describe "with #to_version" do before do @@ -85,16 +66,16 @@ VERSION = 1.9 def to_version Version.new(VERSION.to_s) end end - - @obj = CustomObject.new end + subject { CustomObject.new } + it "returns a Version object" do - assert { Version(@obj).instance_of?(Version) } - assert { Version.new(@obj).instance_of?(Version) } + Version(subject).must_be_instance_of Version + Version.new(subject).must_be_instance_of Version end end end end end