Skip to content

Commit 41ffd1b

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Fix "did you mean" suggestions for unknown commands
Since Ruby 3.4.5, which ships with did_you_mean-2.0.0, RubyGems no longer gives "did you mean" suggestions for unknown commands. This is because did_you_mean-2.0.0 completely removed the SPELL_CHECKERS constant, and attaching "did you mean" to `Gem::UnknownCommandError` errors required this constant to be defined. The fix is to remove conditions on the `SPELL_CHECKERS` constant. rubygems/rubygems@9287cd80ed
1 parent efea70f commit 41ffd1b

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

lib/rubygems/exceptions.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,8 @@ def initialize(unknown_command)
2323
def self.attach_correctable
2424
return if defined?(@attached)
2525

26-
if defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable)
27-
if DidYouMean.respond_to?(:correct_error)
28-
DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
29-
else
30-
DidYouMean::SPELL_CHECKERS["Gem::UnknownCommandError"] =
31-
Gem::UnknownCommandSpellChecker
32-
33-
prepend DidYouMean::Correctable
34-
end
26+
if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
27+
DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
3528
end
3629

3730
@attached = true

test/rubygems/test_gem_command_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_find_command_unknown_suggestions
7878

7979
message = "Unknown command pish".dup
8080

81-
if defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable)
81+
if defined?(DidYouMean)
8282
message << "\nDid you mean? \"push\""
8383
end
8484

0 commit comments

Comments
 (0)