2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-12-20 03:39:12 -05:00
|
|
|
require 'rubygems/commands/server_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsServerCommand < Gem::TestCase
|
2007-12-20 03:39:12 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::ServerCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_options
|
|
|
|
@cmd.send :handle_options, %w[-p 8808 --no-daemon]
|
|
|
|
|
|
|
|
assert_equal false, @cmd.options[:daemon]
|
2010-04-22 04:24:42 -04:00
|
|
|
assert_equal [], @cmd.options[:gemdir]
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 8808, @cmd.options[:port]
|
|
|
|
|
|
|
|
@cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon]
|
|
|
|
|
|
|
|
assert_equal true, @cmd.options[:daemon]
|
2010-04-22 04:24:42 -04:00
|
|
|
assert_equal [File.expand_path('/nonexistent')], @cmd.options[:gemdir]
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 9999, @cmd.options[:port]
|
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def test_handle_options_gemdir
|
|
|
|
@cmd.send :handle_options, %w[--dir a --dir b]
|
|
|
|
|
|
|
|
assert_equal [File.expand_path('a'), File.expand_path('b')],
|
|
|
|
@cmd.options[:gemdir]
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_handle_options_port
|
|
|
|
@cmd.send :handle_options, %w[-p 0]
|
|
|
|
assert_equal 0, @cmd.options[:port]
|
|
|
|
|
|
|
|
@cmd.send :handle_options, %w[-p 65535]
|
|
|
|
assert_equal 65535, @cmd.options[:port]
|
|
|
|
|
2015-10-28 11:43:27 -04:00
|
|
|
@cmd.send :handle_options, %w[-p discard]
|
|
|
|
assert_equal 9, @cmd.options[:port]
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
e = assert_raises OptionParser::InvalidArgument do
|
|
|
|
@cmd.send :handle_options, %w[-p nonexistent]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'invalid argument: -p nonexistent: no such named service',
|
|
|
|
e.message
|
|
|
|
|
|
|
|
e = assert_raises OptionParser::InvalidArgument do
|
|
|
|
@cmd.send :handle_options, %w[-p 65536]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'invalid argument: -p 65536: not a port number',
|
|
|
|
e.message
|
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|