[前][次][番号順一覧][スレッド一覧]

ruby-changes:57546

From: David <ko1@a...>
Date: Thu, 5 Sep 2019 19:10:01 +0900 (JST)
Subject: [ruby-changes:57546] fea91d69a3 (master): [rubygems/rubygems] Don't fail when `uninstall --all` with default gem

https://git.ruby-lang.org/ruby.git/commit/?id=fea91d69a3

From fea91d69a3b4aebd5e69058f9ec51adf2896cdfd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Wed, 21 Aug 2019 20:17:11 +0200
Subject: [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

diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
index 46d9282..20b437d 100644
--- a/lib/rubygems/uninstaller.rb
+++ b/lib/rubygems/uninstaller.rb
@@ -96,6 +96,10 @@ class Gem::Uninstaller https://github.com/ruby/ruby/blob/trunk/lib/rubygems/uninstaller.rb#L96
       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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/uninstaller.rb#L108
     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 4ac0697..927a241 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_uninstall_command.rb#L41
                  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 9dfef7c..bf5ef5b 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -221,13 +221,13 @@ class TestGemUninstaller < Gem::InstallerTestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_uninstaller.rb#L221
 
     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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]