2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/install_command'
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
begin
|
|
|
|
gem "rdoc"
|
|
|
|
rescue Gem::LoadError
|
|
|
|
# ignore
|
|
|
|
end
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsInstallCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::InstallCommand.new
|
|
|
|
@cmd.options[:generate_rdoc] = false
|
|
|
|
@cmd.options[:generate_ri] = false
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_exclude_prerelease
|
2011-05-31 23:45:05 -04:00
|
|
|
util_setup_fake_fetcher :prerelease
|
|
|
|
util_setup_spec_fetcher
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2.cache_file)
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2_pre.cache_file)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
@cmd.options[:args] = [@a2.name]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
e = assert_raises Gem::SystemExitException do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 0, e.exit_code, @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
|
|
|
|
refute_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_explicit_version_includes_prerelease
|
2011-05-31 23:45:05 -04:00
|
|
|
util_setup_fake_fetcher :prerelease
|
|
|
|
util_setup_spec_fetcher
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2.cache_file)
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2_pre.cache_file)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
@cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s,
|
|
|
|
"--no-ri", "--no-rdoc"]
|
2009-06-09 17:38:59 -04:00
|
|
|
assert @cmd.options[:prerelease]
|
|
|
|
assert @cmd.options[:version].satisfied_by?(@a2_pre.version)
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
e = assert_raises Gem::SystemExitException do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 0, e.exit_code, @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
|
|
|
|
assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_include_dependencies
|
|
|
|
@cmd.options[:include_dependencies] = true
|
|
|
|
@cmd.options[:args] = []
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises Gem::CommandLineError do
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
output = @ui.output.split "\n"
|
|
|
|
assert_equal "INFO: `gem install -y` is now default and will be removed",
|
|
|
|
output.shift
|
|
|
|
assert_equal "INFO: use --ignore-dependencies to install only the gems you list",
|
|
|
|
output.shift
|
|
|
|
assert output.empty?, output.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_local
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
@cmd.options[:domain] = :local
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mv @a2.cache_file, @tempdir
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.options[:args] = [@a2.name]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
orig_dir = Dir.pwd
|
|
|
|
begin
|
|
|
|
Dir.chdir @tempdir
|
2008-09-25 06:13:50 -04:00
|
|
|
e = assert_raises Gem::SystemExitException do
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 0, e.exit_code
|
2007-11-10 02:48:56 -05:00
|
|
|
ensure
|
|
|
|
Dir.chdir orig_dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal "Successfully installed #{@a2.full_name}", out.shift
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "1 gem installed", out.shift
|
|
|
|
assert out.empty?, out.inspect
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_no_user_install
|
|
|
|
skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
|
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
@cmd.options[:user_install] = false
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mv @a2.cache_file, @tempdir
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
@cmd.options[:args] = [@a2.name]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
orig_dir = Dir.pwd
|
|
|
|
begin
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.chmod 0755, @userhome
|
|
|
|
FileUtils.chmod 0555, @gemhome
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
Dir.chdir @tempdir
|
|
|
|
assert_raises Gem::FilePermissionError do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
Dir.chdir orig_dir
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.chmod 0755, @gemhome
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_local_missing
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
@cmd.options[:domain] = :local
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.options[:args] = %w[no_such_gem]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
2008-09-25 06:13:50 -04:00
|
|
|
e = assert_raises Gem::SystemExitException do
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 2, e.exit_code
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# HACK no repository was checked
|
2010-04-22 04:24:42 -04:00
|
|
|
assert_match(/ould not find a valid gem 'no_such_gem'/, @ui.error)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_no_gem
|
|
|
|
@cmd.options[:args] = %w[]
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises Gem::CommandLineError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_nonexistent
|
|
|
|
util_setup_fake_fetcher
|
2008-06-17 18:04:18 -04:00
|
|
|
util_setup_spec_fetcher
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[nonexistent]
|
|
|
|
|
|
|
|
use_ui @ui do
|
2008-09-25 06:13:50 -04:00
|
|
|
e = assert_raises Gem::SystemExitException do
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 2, e.exit_code
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def test_execute_nonexistent_with_hint
|
|
|
|
misspelled = "nonexistent_with_hint"
|
|
|
|
correctly_spelled = "non_existent_with_hint"
|
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
2011-03-07 03:44:45 -05:00
|
|
|
util_setup_spec_fetcher quick_spec(correctly_spelled, '2')
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = [misspelled]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
e = assert_raises Gem::SystemExitException do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 2, e.exit_code
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = "ERROR: Could not find a valid gem 'nonexistent_with_hint' (>= 0) in any repository
|
|
|
|
ERROR: Possible alternatives: non_existent_with_hint
|
|
|
|
"
|
|
|
|
|
|
|
|
assert_equal expected, @ui.error
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_prerelease
|
2011-05-31 23:45:05 -04:00
|
|
|
util_setup_fake_fetcher :prerelease
|
|
|
|
util_clear_gems
|
2009-06-09 17:38:59 -04:00
|
|
|
util_setup_spec_fetcher @a2, @a2_pre
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2.cache_file)
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2_pre.cache_file)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
@cmd.options[:prerelease] = true
|
|
|
|
@cmd.options[:args] = [@a2_pre.name]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
e = assert_raises Gem::SystemExitException do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 0, e.exit_code, @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
|
|
|
|
assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_remote
|
|
|
|
@cmd.options[:generate_rdoc] = true
|
|
|
|
@cmd.options[:generate_ri] = true
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
util_setup_fake_fetcher
|
2011-05-31 23:45:05 -04:00
|
|
|
util_setup_spec_fetcher
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@a2.cache_file)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.options[:args] = [@a2.name]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
2008-09-25 06:13:50 -04:00
|
|
|
e = assert_raises Gem::SystemExitException do
|
2009-06-09 17:38:59 -04:00
|
|
|
capture_io do
|
2009-01-22 02:28:35 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
assert_equal 0, e.exit_code
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal "Successfully installed #{@a2.full_name}", out.shift
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "1 gem installed", out.shift
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal "Installing ri documentation for #{@a2.full_name}...",
|
2007-11-10 02:48:56 -05:00
|
|
|
out.shift
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal "Installing RDoc documentation for #{@a2.full_name}...",
|
2007-11-10 02:48:56 -05:00
|
|
|
out.shift
|
|
|
|
assert out.empty?, out.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_two
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
@cmd.options[:domain] = :local
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mv @a2.cache_file, @tempdir
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mv @b2.cache_file, @tempdir
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.options[:args] = [@a2.name, @b2.name]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
orig_dir = Dir.pwd
|
|
|
|
begin
|
|
|
|
Dir.chdir @tempdir
|
2008-09-25 06:13:50 -04:00
|
|
|
e = assert_raises Gem::SystemExitException do
|
2008-03-31 18:40:06 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
assert_equal 0, e.exit_code
|
2007-11-10 02:48:56 -05:00
|
|
|
ensure
|
|
|
|
Dir.chdir orig_dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal "Successfully installed #{@a2.full_name}", out.shift
|
|
|
|
assert_equal "Successfully installed #{@b2.full_name}", out.shift
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "2 gems installed", out.shift
|
|
|
|
assert out.empty?, out.inspect
|
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def test_execute_conservative
|
|
|
|
util_setup_fake_fetcher
|
2011-05-31 23:45:05 -04:00
|
|
|
util_setup_spec_fetcher
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] =
|
2011-05-31 23:45:05 -04:00
|
|
|
read_binary(@b2.cache_file)
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
uninstall_gem(@b2)
|
|
|
|
|
|
|
|
@cmd.options[:conservative] = true
|
|
|
|
|
|
|
|
@cmd.options[:args] = [@a2.name, @b2.name]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
orig_dir = Dir.pwd
|
|
|
|
begin
|
|
|
|
Dir.chdir @tempdir
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_raises Gem::SystemExitException do
|
2011-01-18 19:08:49 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
Dir.chdir orig_dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal "", @ui.error
|
2011-01-18 19:08:49 -05:00
|
|
|
assert_equal "Successfully installed #{@b2.full_name}", out.shift
|
|
|
|
assert_equal "1 gem installed", out.shift
|
|
|
|
assert out.empty?, out.inspect
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|