From 375f527ded72cd20374144dd605e0177945b9fae Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 1 Feb 2023 18:24:21 +0900 Subject: [PATCH] [rubygems/rubygems] Introduce to specify deprecated version for rubygems_deprecate_command. We sometimes to remove minor command without bumping major version. This feature helps this deprecation process. https://github.com/rubygems/rubygems/commit/41301cd2a8 --- lib/rubygems/deprecate.rb | 4 ++-- test/rubygems/test_gem_command_manager.rb | 25 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb index 5fe0afb6b0..56505512c3 100644 --- a/lib/rubygems/deprecate.rb +++ b/lib/rubygems/deprecate.rb @@ -143,7 +143,7 @@ module Gem::Deprecate end # Deprecation method to deprecate Rubygems commands - def rubygems_deprecate_command + def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) class_eval do define_method "deprecated?" do true @@ -151,7 +151,7 @@ module Gem::Deprecate define_method "deprecation_warning" do msg = [ "#{self.command} command is deprecated", - ". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}.\n", + ". It will be removed in Rubygems #{version}.\n", ] alert_warning "#{msg.join}" unless Gem::Deprecate.skip diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index 6b34156187..8108dc0870 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -371,4 +371,29 @@ class TestGemCommandManager < Gem::TestCase ensure Gem::Commands.send(:remove_const, :FooCommand) end + + def test_deprecated_command_with_version + require "rubygems/command" + foo_command = Class.new(Gem::Command) do + extend Gem::Deprecate + + rubygems_deprecate_command("9.9.9") + + def execute + say "pew pew!" + end + end + + Gem::Commands.send(:const_set, :FooCommand, foo_command) + @command_manager.register_command(:foo, foo_command.new("foo")) + + use_ui @ui do + @command_manager.process_args(%w[foo]) + end + + assert_equal "pew pew!\n", @ui.output + assert_match(/WARNING: foo command is deprecated. It will be removed in Rubygems 9.9.9/, @ui.error) + ensure + Gem::Commands.send(:remove_const, :FooCommand) + end end