1require 'rubygems/test_case' 2require 'rubygems/commands/server_command' 3 4class TestGemCommandsServerCommand < Gem::TestCase 5 6 def setup 7 super 8 9 @cmd = Gem::Commands::ServerCommand.new 10 end 11 12 def test_handle_options 13 @cmd.send :handle_options, %w[-p 8808 --no-daemon] 14 15 assert_equal false, @cmd.options[:daemon] 16 assert_equal [], @cmd.options[:gemdir] 17 assert_equal 8808, @cmd.options[:port] 18 19 @cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon] 20 21 assert_equal true, @cmd.options[:daemon] 22 assert_equal [File.expand_path('/nonexistent')], @cmd.options[:gemdir] 23 assert_equal 9999, @cmd.options[:port] 24 end 25 26 def test_handle_options_gemdir 27 @cmd.send :handle_options, %w[--dir a --dir b] 28 29 assert_equal [File.expand_path('a'), File.expand_path('b')], 30 @cmd.options[:gemdir] 31 end 32 33 def test_handle_options_port 34 @cmd.send :handle_options, %w[-p 0] 35 assert_equal 0, @cmd.options[:port] 36 37 @cmd.send :handle_options, %w[-p 65535] 38 assert_equal 65535, @cmd.options[:port] 39 40 @cmd.send :handle_options, %w[-p http] 41 assert_equal 80, @cmd.options[:port] 42 43 e = assert_raises OptionParser::InvalidArgument do 44 @cmd.send :handle_options, %w[-p nonexistent] 45 end 46 47 assert_equal 'invalid argument: -p nonexistent: no such named service', 48 e.message 49 50 e = assert_raises OptionParser::InvalidArgument do 51 @cmd.send :handle_options, %w[-p 65536] 52 end 53 54 assert_equal 'invalid argument: -p 65536: not a port number', 55 e.message 56 end 57 58end 59 60