aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-07-16 21:11:48 -0500
committerJack Nagel2014-07-16 21:11:48 -0500
commit596f3ba0a00b90d6a47ef5860b371f08fc8a72bd (patch)
treeaf5cadf4da79fcf247d947bd7197556877f13832
parenta554b5c9b74bd94470ddd812295efc6ec44fbdde (diff)
downloadbrew-596f3ba0a00b90d6a47ef5860b371f08fc8a72bd.tar.bz2
Raise ArgumentError when a symbol can't be mapped to a version
The fact that this is implemented as a hash lookup is an implementation detail, so don't let the KeyError bubble up.
-rw-r--r--Library/Homebrew/os/mac/version.rb5
-rw-r--r--Library/Homebrew/test/test_version_subclasses.rb5
2 files changed, 9 insertions, 1 deletions
diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb
index ed05ac553..06901b642 100644
--- a/Library/Homebrew/os/mac/version.rb
+++ b/Library/Homebrew/os/mac/version.rb
@@ -14,7 +14,10 @@ module OS
}
def self.from_symbol(sym)
- new(SYMBOLS.fetch(sym))
+ str = SYMBOLS.fetch(sym) do
+ raise ArgumentError, "unknown version #{sym.inspect}"
+ end
+ new(str)
end
def initialize(*args)
diff --git a/Library/Homebrew/test/test_version_subclasses.rb b/Library/Homebrew/test/test_version_subclasses.rb
index 1dbaae47a..9261a7251 100644
--- a/Library/Homebrew/test/test_version_subclasses.rb
+++ b/Library/Homebrew/test/test_version_subclasses.rb
@@ -39,4 +39,9 @@ class MacOSVersionTests < Homebrew::TestCase
assert_operator @v, :===, Version.new("10.7")
assert_operator @v, :<, Version.new("10.8")
end
+
+ def test_from_symbol
+ assert_equal @v, MacOS::Version.from_symbol(:lion)
+ assert_raises(ArgumentError) { MacOS::Version.from_symbol(:foo) }
+ end
end