diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 01ff12a713..df903c3bc7 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -761,12 +761,15 @@ end class DownloadStrategyDetector def self.detect(url, strategy=nil) - if strategy.is_a? Class and strategy.ancestors.include? AbstractDownloadStrategy - strategy - elsif strategy.is_a? Symbol + if strategy.nil? + detect_from_url(url) + elsif Class === strategy && strategy < AbstractDownloadStrategy + strategy + elsif Symbol === strategy detect_from_symbol(strategy) else - detect_from_url(url) + raise TypeError, + "Unknown download strategy specification #{strategy.inspect}" end end diff --git a/Library/Homebrew/test/test_download_strategies.rb b/Library/Homebrew/test/test_download_strategies.rb index ef330de42c..3a330e7976 100644 --- a/Library/Homebrew/test/test_download_strategies.rb +++ b/Library/Homebrew/test/test_download_strategies.rb @@ -51,4 +51,10 @@ class DownloadStrategyDetectorTests < Test::Unit::TestCase @d = DownloadStrategyDetector.detect(Object.new) assert_equal CurlDownloadStrategy, @d end + + def test_raises_when_passed_unrecognized_strategy + assert_raises(TypeError) do + DownloadStrategyDetector.detect("foo", Class.new) + end + end end