aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems/uninstaller.rb13
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb45
-rw-r--r--test/rubygems/test_gem_uninstaller.rb8
3 files changed, 54 insertions, 12 deletions
diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
index 46d92820cb..20b437d472 100644
--- a/lib/rubygems/uninstaller.rb
+++ b/lib/rubygems/uninstaller.rb
@@ -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
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index 4ac06977e3..927a241203 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -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
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index 9dfef7cfda..bf5ef5b4a2 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -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