Disallow initializing Versions with non-strings
Closes Homebrew/homebrew#23553.
This commit is contained in:
parent
e67286369e
commit
383b321119
@ -1,6 +1,19 @@
|
||||
require 'testing_env'
|
||||
require 'version'
|
||||
|
||||
class VersionTests < Test::Unit::TestCase
|
||||
def test_accepts_objects_responding_to_to_str
|
||||
value = stub(:to_str => '0.1')
|
||||
assert_equal '0.1', Version.new(value).to_s
|
||||
end
|
||||
|
||||
def test_raises_for_non_string_objects
|
||||
assert_raises(TypeError) { Version.new(1.1) }
|
||||
assert_raises(TypeError) { Version.new(1) }
|
||||
assert_raises(TypeError) { Version.new(:symbol) }
|
||||
end
|
||||
end
|
||||
|
||||
class VersionComparisonTests < Test::Unit::TestCase
|
||||
include VersionAssertions
|
||||
|
||||
|
||||
@ -163,7 +163,12 @@ class Version
|
||||
end
|
||||
|
||||
def initialize(val, detected=false)
|
||||
@version = val.to_s
|
||||
if val.respond_to?(:to_str)
|
||||
@version = val.to_str
|
||||
else
|
||||
raise TypeError, "Version value must be a string"
|
||||
end
|
||||
|
||||
@detected_from_url = detected
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user