Skip to content

Commit ac24f70

Browse files
committed
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`.
1 parent 7c5ddb7 commit ac24f70

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

lib/rubygems/exceptions.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ def initialize(unknown_command)
2121
end
2222

2323
def self.attach_correctable
24-
return if defined?(@attached)
24+
return if method_defined?(:corrections)
2525

2626
if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
2727
DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
2828
end
29-
30-
@attached = true
3129
end
3230
end
3331

test/rubygems/test_gem_command_manager.rb

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

8080
message = "Unknown command pish".dup
8181

82-
if defined?(DidYouMean)
82+
if e.respond_to?(:corrections)
8383
message << "\nDid you mean? \"push\""
8484
end
8585

0 commit comments

Comments
 (0)