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

ruby-changes:70625

From: David <ko1@a...>
Date: Mon, 27 Dec 2021 22:58:00 +0900 (JST)
Subject: [ruby-changes:70625] be476f38f9 (master): [rubygems/rubygems] Don't crash when updating to an unsupported `rubygems-update` version

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

From be476f38f9a467a25b81dabe42ca120924527395 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Tue, 21 Dec 2021 10:37:46 +0100
Subject: [rubygems/rubygems] Don't crash when updating to an unsupported
 `rubygems-update` version

https://github.com/rubygems/rubygems/commit/b0badcd00a
---
 lib/rubygems/commands/update_command.rb           |  4 +++-
 test/rubygems/test_gem_commands_update_command.rb | 25 +++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index a78f29427f5..3714b003227 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -288,7 +288,9 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L288
 
     installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
     installed_gems = update_gem('rubygems-update', version) if installed_gems.empty?
-    version        = installed_gems.first.version
+    return if installed_gems.empty?
+
+    version = installed_gems.first.version
 
     install_rubygems version
   end
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index e9264f6d148..ce599d5812d 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -106,6 +106,31 @@ class TestGemCommandsUpdateCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_update_command.rb#L106
     assert_empty out
   end
 
+  def test_execute_system_when_latest_does_not_support_your_ruby
+    spec_fetcher do |fetcher|
+      fetcher.download 'rubygems-update', 9 do |s|
+        s.files = %w[setup.rb]
+        s.required_ruby_version = '> 9'
+      end
+    end
+
+    @cmd.options[:args]          = []
+    @cmd.options[:system]        = true
+
+    use_ui @ui do
+      @cmd.execute
+    end
+
+    out = @ui.output.split "\n"
+    assert_equal "Updating rubygems-update", out.shift
+    assert_empty out
+
+    err = @ui.error.split "\n"
+    assert_equal "ERROR:  Error installing rubygems-update:", err.shift
+    assert_equal "\trubygems-update-9 requires Ruby version > 9. The current ruby version is #{Gem.ruby_version}.", err.shift
+    assert_empty err
+  end
+
   def test_execute_system_multiple
     spec_fetcher do |fetcher|
       fetcher.download 'rubygems-update', 8 do |s|
-- 
cgit v1.2.1


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

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