diff options
author | Eric Mueller <nevinera@gmail.com> | 2023-11-29 21:51:55 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-12-01 17:52:37 +0000 |
commit | 079dfa1812e0f23a74c86e271245504b069b4c17 (patch) | |
tree | dabe1eeffdf75a99b7ebfe4f5af059b4bfdefc1f | |
parent | e5e1f9813e23c427cf45a25181b2e6d3cf97411a (diff) | |
download | ruby-079dfa1812e0f23a74c86e271245504b069b4c17.tar.gz |
[rubygems/rubygems] major_deprecation accepts :removed_message
If supplied, it uses that in place of the message for the case where the
deprecation version is already past.
https://github.com/rubygems/rubygems/commit/1deb73663c
-rw-r--r-- | lib/bundler/shared_helpers.rb | 8 | ||||
-rw-r--r-- | spec/bundler/bundler/shared_helpers_spec.rb | 30 |
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index fa7db1c09d..08589eea27 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -117,16 +117,18 @@ module Bundler raise GenericSystemCallError.new(e, "There was an error accessing `#{path}`.") end - def major_deprecation(major_version, message, print_caller_location: false) + def major_deprecation(major_version, message, removed_message: nil, print_caller_location: false) if print_caller_location caller_location = caller_locations(2, 2).first - message = "#{message} (called at #{caller_location.path}:#{caller_location.lineno})" + suffix = " (called at #{caller_location.path}:#{caller_location.lineno})" + message += suffix + removed_message += suffix if removed_message end bundler_major_version = Bundler.bundler_major_version if bundler_major_version > major_version require_relative "errors" - raise DeprecatedError, "[REMOVED] #{message}" + raise DeprecatedError, "[REMOVED] #{removed_message || message}" end return unless bundler_major_version >= major_version && prints_major_deprecations? diff --git a/spec/bundler/bundler/shared_helpers_spec.rb b/spec/bundler/bundler/shared_helpers_spec.rb index ae44e48c71..e081385bbe 100644 --- a/spec/bundler/bundler/shared_helpers_spec.rb +++ b/spec/bundler/bundler/shared_helpers_spec.rb @@ -522,4 +522,34 @@ RSpec.describe Bundler::SharedHelpers do end end end + + describe "#major_deprecation" do + before { allow(Bundler).to receive(:bundler_major_version).and_return(37) } + before { allow(Bundler.ui).to receive(:warn) } + + it "prints and raises nothing below the deprecated major version" do + subject.major_deprecation(38, "Message") + subject.major_deprecation(39, "Message", :removed_message => "Removal", :print_caller_location => true) + expect(Bundler.ui).not_to have_received(:warn) + end + + it "prints but does not raise _at_ the deprecated major version" do + subject.major_deprecation(37, "Message") + subject.major_deprecation(37, "Message", :removed_message => "Removal") + expect(Bundler.ui).to have_received(:warn).with("[DEPRECATED] Message").twice + + subject.major_deprecation(37, "Message", :print_caller_location => true) + expect(Bundler.ui).to have_received(:warn). + with(a_string_matching(/^\[DEPRECATED\] Message \(called at .*:\d+\)$/)) + end + + it "raises the appropriate errors when _past_ the deprecated major version" do + expect { subject.major_deprecation(36, "Message") }. + to raise_error(Bundler::DeprecatedError, "[REMOVED] Message") + expect { subject.major_deprecation(36, "Message", :removed_message => "Removal") }. + to raise_error(Bundler::DeprecatedError, "[REMOVED] Removal") + expect { subject.major_deprecation(35, "Message", :removed_message => "Removal", :print_caller_location => true) }. + to raise_error(Bundler::DeprecatedError, /^\[REMOVED\] Removal \(called at .*:\d+\)$/) + end + end end |