Align the conditions for did_you_mean

Probably due to the testing order, sometimes it looks like that
`Gem::UnknownCommandError` happens to be used without registered in
`DidYouMean`.
This commit is contained in:
Nobuyoshi Nakada 2025-09-08 21:01:29 +09:00
parent 7c5ddb793b
commit ac24f70fb0
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
2 changed files with 2 additions and 4 deletions

View File

@ -21,13 +21,11 @@ class Gem::UnknownCommandError < Gem::Exception
end
def self.attach_correctable
return if defined?(@attached)
return if method_defined?(:corrections)
if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
end
@attached = true
end
end

View File

@ -79,7 +79,7 @@ class TestGemCommandManager < Gem::TestCase
message = "Unknown command pish".dup
if defined?(DidYouMean)
if e.respond_to?(:corrections)
message << "\nDid you mean? \"push\""
end