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.
b44845aa1d
This commit is contained in:
parent
f9f6a3d793
commit
fea91d69a3
3 changed files with 54 additions and 12 deletions
|
@ -96,6 +96,10 @@ class Gem::Uninstaller
|
||||||
spec.default_gem?
|
spec.default_gem?
|
||||||
end
|
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|
|
list, other_repo_specs = list.partition do |spec|
|
||||||
@gem_home == spec.base_dir or
|
@gem_home == spec.base_dir or
|
||||||
(@user_install and spec.base_dir == Gem.user_dir)
|
(@user_install and spec.base_dir == Gem.user_dir)
|
||||||
|
@ -104,14 +108,7 @@ class Gem::Uninstaller
|
||||||
list.sort!
|
list.sort!
|
||||||
|
|
||||||
if list.empty?
|
if list.empty?
|
||||||
if other_repo_specs.empty?
|
return unless other_repo_specs.any?
|
||||||
if default_specs.any?
|
|
||||||
message =
|
|
||||||
"gem #{@gem.inspect} cannot be uninstalled " +
|
|
||||||
"because it is a default gem"
|
|
||||||
raise Gem::InstallError, message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
other_repos = other_repo_specs.map { |spec| spec.base_dir }.uniq
|
other_repos = other_repo_specs.map { |spec| spec.base_dir }.uniq
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,51 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
|
||||||
Gem::Specification.all_names.sort
|
Gem::Specification.all_names.sort
|
||||||
end
|
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
|
def test_execute_dependency_order
|
||||||
initial_install
|
initial_install
|
||||||
|
|
||||||
|
|
|
@ -221,13 +221,13 @@ class TestGemUninstaller < Gem::InstallerTestCase
|
||||||
|
|
||||||
uninstaller = Gem::Uninstaller.new spec.name, :executables => true
|
uninstaller = Gem::Uninstaller.new spec.name, :executables => true
|
||||||
|
|
||||||
e = assert_raises Gem::InstallError do
|
use_ui @ui do
|
||||||
uninstaller.uninstall
|
uninstaller.uninstall
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal 'gem "default" cannot be uninstalled ' +
|
lines = @ui.output.split("\n")
|
||||||
'because it is a default gem',
|
|
||||||
e.message
|
assert_equal 'Gem default-2 cannot be uninstalled because it is a default gem', lines.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uninstall_default_gem_with_same_version
|
def test_uninstall_default_gem_with_same_version
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue