2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2011-01-29 02:46:47 +03:00
|
|
|
require 'rubygems/test_case'
|
2007-12-20 11:39:12 +03:00
|
|
|
require 'rubygems/commands/server_command'
|
|
|
|
|
2011-01-29 02:46:47 +03:00
|
|
|
class TestGemCommandsServerCommand < Gem::TestCase
|
2007-12-20 11:39:12 +03: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 12:24:42 +04:00
|
|
|
assert_equal [], @cmd.options[:gemdir]
|
2007-12-20 11:39:12 +03: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 12:24:42 +04:00
|
|
|
assert_equal [File.expand_path('/nonexistent')], @cmd.options[:gemdir]
|
2007-12-20 11:39:12 +03:00
|
|
|
assert_equal 9999, @cmd.options[:port]
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2010-04-22 12: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-10 01: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 18:43:27 +03:00
|
|
|
@cmd.send :handle_options, %w[-p discard]
|
|
|
|
assert_equal 9, @cmd.options[:port]
|
2009-06-10 01: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 11:39:12 +03:00
|
|
|
end
|
|
|
|
|