Skip to content

Commit

Permalink
Make sure did_you_mean feature works when the gem is available
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Nov 10, 2018
1 parent f9f7488 commit 36c3646
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ group :test do
else
gem "webmock"
end
if RUBY_VERSION >= '2.5.0'
gem 'did_you_mean'

This comment has been minimized.

Copy link
@mathieujobin

mathieujobin Nov 10, 2018

ah, needs to be part of gemspec ...

end
end

gemspec
23 changes: 10 additions & 13 deletions lib/thor/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ class Thor
begin
require 'did_you_mean'

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

This comment has been minimized.

Copy link
@mathieujobin

mathieujobin Nov 10, 2018

bundler-audit now crash with thor 0.20.1

/home/mathieu/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/thor-0.20.1/lib/thor/error.rb:12:in `<module:DidYouMean>': uninitialized constant Thor::DidYouMean::SpellChecker (NameError)
def initialize(dictionary)
@dictionary = dictionary
end
end

Expand Down Expand Up @@ -43,7 +41,7 @@ def corrections
end

def spell_checker
DidYouMean::NoKwargSpellChecker.new(error.all_commands)
NoKwargSpellChecker.new(error.all_commands)
end
end

Expand Down Expand Up @@ -85,8 +83,7 @@ def corrections
end

def spell_checker
@spell_checker ||=
DidYouMean::NoKwargSpellChecker.new(error.switches)
@spell_checker ||= NoKwargSpellChecker.new(error.switches)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def hello

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

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

0 comments on commit 36c3646

Please sign in to comment.