1require "rubygems" 2require "rubygems/test_case" 3require "rubygems/commands/help_command" 4require "rubygems/package" 5require "rubygems/command_manager" 6require File.expand_path('../rubygems_plugin', __FILE__) 7 8class TestGemCommandsHelpCommand < Gem::TestCase 9 def setup 10 super 11 12 @cmd = Gem::Commands::HelpCommand.new 13 14 load File.expand_path('../rubygems_plugin.rb', __FILE__) unless 15 Gem::Commands.const_defined? :InterruptCommand 16 end 17 18 def test_gem_help_bad 19 util_gem 'bad' do |out, err| 20 assert_equal('', out) 21 assert_match(/Unknown command bad. Try gem help commands\n/, err) 22 end 23 end 24 25 def test_gem_help_platforms 26 util_gem 'platforms' do |out, err| 27 assert_match(/x86-freebsd/, out) 28 assert_equal '', err 29 end 30 end 31 32 def test_gem_help_commands 33 mgr = Gem::CommandManager.new 34 35 util_gem 'commands' do |out, err| 36 mgr.command_names.each do |cmd| 37 assert_match(/\s+#{cmd}\s+\S+/, out) 38 end 39 assert_equal '', err 40 41 refute_match 'No command found for ', out 42 end 43 end 44 45 def test_gem_no_args_shows_help 46 util_gem do |out, err| 47 assert_match(/Usage:/, out) 48 assert_match(/gem install/, out) 49 assert_equal '', err 50 end 51 end 52 53 def util_gem *args 54 @cmd.options[:args] = args 55 56 use_ui @ui do 57 Dir.chdir @tempdir do 58 @cmd.execute 59 end 60 end 61 62 yield @ui.output, @ui.error 63 end 64end 65