1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Don't fail when uninstall --all with default gem

Instead, display an informative message saying that uninstallation of
specific versions is being skipped because of being default gems.

https://github.com/rubygems/rubygems/commit/b44845aa1d
This commit is contained in:
David Rodríguez 2019-08-21 20:17:11 +02:00 committed by Hiroshi SHIBATA
parent f9f6a3d793
commit fea91d69a3
3 changed files with 54 additions and 12 deletions

View file

@ -96,6 +96,10 @@ class Gem::Uninstaller
spec.default_gem?
end
default_specs.each do |default_spec|
say "Gem #{default_spec.full_name} cannot be uninstalled because it is a default gem"
end
list, other_repo_specs = list.partition do |spec|
@gem_home == spec.base_dir or
(@user_install and spec.base_dir == Gem.user_dir)
@ -104,14 +108,7 @@ class Gem::Uninstaller
list.sort!
if list.empty?
if other_repo_specs.empty?
if default_specs.any?
message =
"gem #{@gem.inspect} cannot be uninstalled " +
"because it is a default gem"
raise Gem::InstallError, message
end
end
return unless other_repo_specs.any?
other_repos = other_repo_specs.map { |spec| spec.base_dir }.uniq

View file

@ -41,6 +41,51 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
Gem::Specification.all_names.sort
end
def test_execute_all_named_default_single
z_1 = new_default_spec 'z', '1'
install_default_gems z_1
assert_includes Gem::Specification.all_names, 'z-1'
@cmd.options[:all] = true
@cmd.options[:args] = %w[z]
use_ui @ui do
@cmd.execute
end
assert_equal %w[z-1], Gem::Specification.all_names.sort
output = @ui.output.split "\n"
assert_equal 'Gem z-1 cannot be uninstalled because it is a default gem', output.shift
end
def test_execute_all_named_default_multiple
z_1 = new_default_spec 'z', '1'
install_default_gems z_1
z_2, = util_gem 'z', 2
install_gem z_2
assert_includes Gem::Specification.all_names, 'z-1'
assert_includes Gem::Specification.all_names, 'z-2'
@cmd.options[:all] = true
@cmd.options[:args] = %w[z]
use_ui @ui do
@cmd.execute
end
assert_equal %w[z-1], Gem::Specification.all_names.sort
output = @ui.output.split "\n"
assert_equal 'Gem z-1 cannot be uninstalled because it is a default gem', output.shift
assert_equal 'Successfully uninstalled z-2', output.shift
end
def test_execute_dependency_order
initial_install

View file

@ -221,13 +221,13 @@ class TestGemUninstaller < Gem::InstallerTestCase
uninstaller = Gem::Uninstaller.new spec.name, :executables => true
e = assert_raises Gem::InstallError do
use_ui @ui do
uninstaller.uninstall
end
assert_equal 'gem "default" cannot be uninstalled ' +
'because it is a default gem',
e.message
lines = @ui.output.split("\n")
assert_equal 'Gem default-2 cannot be uninstalled because it is a default gem', lines.shift
end
def test_uninstall_default_gem_with_same_version