зеркало из https://github.com/github/ruby.git
[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
This commit is contained in:
Родитель
e5e1f9813e
Коммит
079dfa1812
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче