Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rubygems/deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def deprecate(name, repl, year, month)
msg = [
"NOTE: #{target}#{name} is deprecated",
repl == :none ? " with no replacement" : "; use #{repl} instead",
format(". It will be removed on or after %4d-%02d.", year, month),
Kernel.format(". It will be removed on or after %4d-%02d.", year, month),
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
]
warn "#{msg.join}." unless Gem::Deprecate.skip
Expand Down
29 changes: 29 additions & 0 deletions test/rubygems/test_deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ def bar_kwarg(message:)
deprecate :foo_kwarg, :bar_kwarg, 2099, 3
end

class ThingWithFormat
extend Gem::Deprecate
attr_accessor :message
def foo
@message = "foo"
end

def bar
@message = "bar"
end
deprecate :foo, :bar, 2099, 3

def format
raise "ThingWithFormat#format should not be called"
end
end

def test_deprecated_method_calls_the_old_method
capture_output do
thing = Thing.new
Expand Down Expand Up @@ -161,4 +178,16 @@ def test_deprecated_method_outputs_a_warning_old_way
assert_match(/OtherThing#foo_kwarg is deprecated; use bar_kwarg instead\./, err)
assert_match(/on or after 2099-03/, err)
end

def test_deprecated_method_when_class_overrides_format
out, err = capture_output do
thing = ThingWithFormat.new
thing.foo
assert_equal "foo", thing.message
end

assert_equal "", out
assert_match(/ThingWithFormat#foo is deprecated; use bar instead\./, err)
assert_match(/on or after 2099-03/, err)
end
end