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 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 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
92 @cmd.options[:args] = %w[nonexistent]
95 e = assert_raises Gem::SystemExitException do
98 assert_equal 2, e.exit_code
101 assert_equal "ERROR: could not find nonexistent locally or in a repository\n",
105 def test_execute_remote
106 @cmd.options[:generate_rdoc] = true
107 @cmd.options[:generate_ri] = true
108 util_setup_fake_fetcher
110 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
112 @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] =
113 read_binary(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
115 @cmd.options[:args] = [@a2.name]
118 e = assert_raises Gem::SystemExitException do
121 assert_equal 0, e.exit_code
124 out = @ui.output.split "\n"
125 assert_match %r|Bulk updating|, out.shift
126 assert_equal "Successfully installed #{@a2.full_name}", out.shift
127 assert_equal "1 gem installed", out.shift
128 assert_equal "Installing ri documentation for #{@a2.full_name}...",
130 assert_equal "Installing RDoc documentation for #{@a2.full_name}...",
132 assert out.empty?, out.inspect
136 util_setup_fake_fetcher
137 @cmd.options[:domain] = :local
139 FileUtils.mv File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"),
142 FileUtils.mv File.join(@gemhome, 'cache', "#{@b2.full_name}.gem"),
145 @cmd.options[:args] = [@a2.name, @b2.name]
151 e = assert_raises Gem::SystemExitException do
154 assert_equal 0, e.exit_code
160 out = @ui.output.split "\n"
161 assert_equal "Successfully installed #{@a2.full_name}", out.shift
162 assert_equal "Successfully installed #{@b2.full_name}", out.shift
163 assert_equal "2 gems installed", out.shift
164 assert out.empty?, out.inspect