2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/install_command'
5 class TestGemCommandsInstallCommand < RubyGemTestCase
10 @cmd = Gem::Commands::InstallCommand.new
11 @cmd.options[:generate_rdoc] = false
12 @cmd.options[:generate_ri] = false
15 def test_execute_include_dependencies
16 @cmd.options[:include_dependencies] = true
17 @cmd.options[:args] = []
19 assert_raise Gem::CommandLineError do
25 output = @ui.output.split "\n"
26 assert_equal "INFO: `gem install -y` is now default and will be removed",
28 assert_equal "INFO: use --ignore-dependencies to install only the gems you list",
30 assert output.empty?, output.inspect
33 def test_execute_local
34 util_setup_fake_fetcher
35 @cmd.options[:domain] = :local
37 FileUtils.mv File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"),
40 @cmd.options[:args] = [@a2.name]
46 e = assert_raises Gem::SystemExitException do
49 assert_equal 0, e.exit_code
55 out = @ui.output.split "\n"
56 assert_equal "Successfully installed #{@a2.full_name}", out.shift
57 assert_equal "1 gem installed", out.shift
58 assert out.empty?, out.inspect
61 def test_execute_local_missing
62 util_setup_fake_fetcher
63 @cmd.options[:domain] = :local
65 @cmd.options[:args] = %w[no_such_gem]
68 e = assert_raises Gem::SystemExitException do
71 assert_equal 2, e.exit_code
74 # HACK no repository was checked
75 assert_equal "ERROR: could not find gem no_such_gem locally or in a repository\n",
79 def test_execute_no_gem
80 @cmd.options[:args] = %w[]
82 assert_raise Gem::CommandLineError do
87 def test_execute_nonexistent
88 util_setup_fake_fetcher
89 util_setup_spec_fetcher
91 @cmd.options[:args] = %w[nonexistent]
94 e = assert_raises Gem::SystemExitException do
97 assert_equal 2, e.exit_code
100 assert_equal "ERROR: could not find gem nonexistent locally or in a repository\n",
104 def test_execute_remote
105 @cmd.options[:generate_rdoc] = true
106 @cmd.options[:generate_ri] = true
108 util_setup_fake_fetcher
109 util_setup_spec_fetcher @a2
111 @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
112 read_binary(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
114 @cmd.options[:args] = [@a2.name]
117 e = assert_raises Gem::SystemExitException do
120 assert_equal 0, e.exit_code
123 out = @ui.output.split "\n"
124 assert_equal "Successfully installed #{@a2.full_name}", out.shift
125 assert_equal "1 gem installed", out.shift
126 assert_equal "Installing ri documentation for #{@a2.full_name}...",
128 assert_equal "Installing RDoc documentation for #{@a2.full_name}...",
130 assert out.empty?, out.inspect
134 util_setup_fake_fetcher
135 @cmd.options[:domain] = :local
137 FileUtils.mv File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"),
140 FileUtils.mv File.join(@gemhome, 'cache', "#{@b2.full_name}.gem"),
143 @cmd.options[:args] = [@a2.name, @b2.name]
149 e = assert_raises Gem::SystemExitException do
152 assert_equal 0, e.exit_code
158 out = @ui.output.split "\n"
159 assert_equal "Successfully installed #{@a2.full_name}", out.shift
160 assert_equal "Successfully installed #{@b2.full_name}", out.shift
161 assert_equal "2 gems installed", out.shift
162 assert out.empty?, out.inspect