Skip to content

Commit 36c3646

Browse files
committed
Make sure did_you_mean feature works when the gem is available
1 parent f9f7488 commit 36c3646

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ group :test do
3333
else
3434
gem "webmock"
3535
end
36+
if RUBY_VERSION >= '2.5.0'
37+
gem 'did_you_mean'
38+
end
3639
end
3740

3841
gemspec

lib/thor/error.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ class Thor
33
begin
44
require 'did_you_mean'
55

6-
module DidYouMean
7-
# In order to support versions of Ruby that don't have keyword
8-
# arguments, we need our own spell checker class that doesn't take key
9-
# words. Even though this code wouldn't be hit because of the check
10-
# above, it's still necessary because the interpreter would otherwise be
11-
# unable to parse the file.
12-
class NoKwargSpellChecker < SpellChecker
13-
def initialize(dictionary)
14-
@dictionary = dictionary
15-
end
6+
# In order to support versions of Ruby that don't have keyword
7+
# arguments, we need our own spell checker class that doesn't take key
8+
# words. Even though this code wouldn't be hit because of the check
9+
# above, it's still necessary because the interpreter would otherwise be
10+
# unable to parse the file.
11+
class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
12+
def initialize(dictionary)
13+
@dictionary = dictionary
1614
end
1715
end
1816

@@ -43,7 +41,7 @@ def corrections
4341
end
4442

4543
def spell_checker
46-
DidYouMean::NoKwargSpellChecker.new(error.all_commands)
44+
NoKwargSpellChecker.new(error.all_commands)
4745
end
4846
end
4947

@@ -85,8 +83,7 @@ def corrections
8583
end
8684

8785
def spell_checker
88-
@spell_checker ||=
89-
DidYouMean::NoKwargSpellChecker.new(error.switches)
86+
@spell_checker ||= NoKwargSpellChecker.new(error.switches)
9087
end
9188
end
9289

spec/base_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def hello
264264

265265
it "suggests commands that are similar if there is a typo" do
266266
expected = "Could not find command \"paintz\" in \"barn\" namespace.\n"
267-
expected << "Did you mean? \"paint\"" if Thor::Correctable
267+
expected << "Did you mean? \"paint\"\n" if Thor::Correctable
268268

269269
expect(capture(:stderr) { Barn.start(%w(paintz)) }).to eq(expected)
270270
end

0 commit comments

Comments
 (0)