Browse files

Merge branch 'refs/heads/issue_40'

  • Loading branch information...
2 parents 7e27a1e + 6dee6df commit 68eb642f4c0c95edc046d72ca8bb18708f42c54c @olbrich committed May 13, 2012
Showing with 9 additions and 3 deletions.
  1. +1 −0 lib/ruby_units/unit.rb
  2. +8 −3 spec/ruby-units/unit_spec.rb
View
1 lib/ruby_units/unit.rb
@@ -314,6 +314,7 @@ def initialize(*options)
@unit_name = nil
@signature = nil
@output = {}
+ raise ArgumentError, "Invalid Unit Format" if options[0].nil?
if options.size == 2
# options[0] is the scalar
# options[1] is a unit string
View
11 spec/ruby-units/unit_spec.rb
@@ -427,7 +427,7 @@
its(:temperature_scale) {should be_nil}
end
- describe Unit.new("1 m^2 s^-2") do
+ describe Unit("1 m^2 s^-2") do
it {should be_an_instance_of Unit}
its(:scalar) {should be_an Integer}
its(:units) {should == "m^2/s^2"}
@@ -441,7 +441,7 @@
its(:temperature_scale) {should be_nil}
end
- describe Unit.new(1,"m^2","s^2") do
+ describe Unit(1,"m^2","s^2") do
it {should be_an_instance_of Unit}
its(:scalar) {should be_an Integer}
its(:units) {should == "m^2/s^2"}
@@ -456,7 +456,7 @@
end
#scientific notation
- describe Unit.new("1e6 cells") do
+ describe Unit("1e6 cells") do
it {should be_an_instance_of Unit}
its(:scalar) {should be_an Integer}
its(:scalar) {should == 1e6 }
@@ -568,6 +568,11 @@
expect {Unit("-100 tempR")}.to raise_error(ArgumentError,"Temperatures must not be less than absolute zero")
expect {Unit("-500/9 tempR")}.to raise_error(ArgumentError,"Temperatures must not be less than absolute zero")
end
+
+ specify "no nil scalar" do
+ expect {Unit(nil, "feet")}.to raise_error(ArgumentError, "Invalid Unit Format")
+ expect {Unit(nil, "feet", "min")}.to raise_error(ArgumentError, "Invalid Unit Format")
+ end
end

0 comments on commit 68eb642

Please sign in to comment.