Tests for AbstractDownloadStrategy

This commit is contained in:
Jack Nagel 2013-04-07 00:49:56 -05:00
parent 9db0e68eb6
commit 2288f63197
2 changed files with 38 additions and 1 deletions

View File

@ -8,6 +8,7 @@ class AbstractDownloadStrategy
end end
def expand_safe_system_args args def expand_safe_system_args args
args = args.dup
args.each_with_index do |arg, ii| args.each_with_index do |arg, ii|
if arg.is_a? Hash if arg.is_a? Hash
unless ARGV.verbose? unless ARGV.verbose?
@ -20,7 +21,7 @@ class AbstractDownloadStrategy
end end
# 2 as default because commands are eg. svn up, git pull # 2 as default because commands are eg. svn up, git pull
args.insert(2, '-q') unless ARGV.verbose? args.insert(2, '-q') unless ARGV.verbose?
return args args
end end
def quiet_safe_system *args def quiet_safe_system *args

View File

@ -1,6 +1,42 @@
require 'testing_env' require 'testing_env'
require 'download_strategy' require 'download_strategy'
require 'bottles' # XXX: hoist these regexps into constants in Pathname? require 'bottles' # XXX: hoist these regexps into constants in Pathname?
require 'hardware' # XXX: wat. fix this require mess!
class SoftwareSpecDouble
attr_reader :url, :specs
def initialize(url="http://foo.com/bar.tar.gz", specs={})
@url = url
@specs = specs
end
end
class AbstractDownloadStrategyTests < Test::Unit::TestCase
def setup
@name = "foo"
@package = SoftwareSpecDouble.new
@strategy = AbstractDownloadStrategy.new(@name, @package)
@args = %w{foo bar baz}
end
def test_expand_safe_system_args_with_explicit_quiet_flag
@args << { :quiet_flag => '--flag' }
expanded_args = @strategy.expand_safe_system_args(@args)
assert_equal %w{foo bar baz --flag}, expanded_args
end
def test_expand_safe_system_args_with_implicit_quiet_flag
expanded_args = @strategy.expand_safe_system_args(@args)
assert_equal %w{foo bar -q baz}, expanded_args
end
def test_expand_safe_system_args_does_not_mutate_argument
result = @strategy.expand_safe_system_args(@args)
assert_equal %w{foo bar baz}, @args
assert_not_same @args, result
end
end
class DownloadStrategyDetectorTests < Test::Unit::TestCase class DownloadStrategyDetectorTests < Test::Unit::TestCase
def setup def setup