Reject versions that aren't strings

This commit is contained in:
Jack Nagel 2013-06-28 21:17:12 -05:00
parent 033ef09518
commit f6536e9c8b
2 changed files with 8 additions and 0 deletions

View File

@ -40,6 +40,8 @@ class SoftwareSpec
when nil then Version.detect(url, specs)
when String then Version.new(val)
when Hash then Version.new_with_scheme(*val.shift)
else
raise TypeError, "version '#{val.inspect}' should be a string"
end
end

View File

@ -66,6 +66,12 @@ class SoftwareSpecTests < Test::Unit::TestCase
assert @spec.version.detected_from_url?
end
def test_rejects_non_string_versions
assert_raises(TypeError) { @spec.version(1) }
assert_raises(TypeError) { @spec.version(2.0) }
assert_raises(TypeError) { @spec.version(Object.new) }
end
def test_mirrors
assert_empty @spec.mirrors
@spec.mirror('foo')