Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added did you mean to rake #221

Merged
merged 1 commit into from
Sep 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/rake/task_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,21 @@ def [](task_name, scopes=nil)
self.lookup(task_name, scopes) or
enhance_with_matching_rule(task_name) or
synthesize_file_task(task_name) or
fail "Don't know how to build task '#{task_name}' (see --tasks)"
fail generate_message_for_undefined_task(task_name)
end

def generate_message_for_undefined_task(task_name)
message = "Don't know how to build task '#{task_name}' (see --tasks)"

suggestion_message = \
if defined?(::DidYouMean::SpellChecker) && defined?(::DidYouMean::Formatter)
suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s)
::DidYouMean::Formatter.new(suggestions).to_s
else
""
end

message + suggestion_message
end

def synthesize_file_task(task_name) # :nodoc:
Expand Down
13 changes: 12 additions & 1 deletion test/test_rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,15 @@ def test_source_is_first_prerequisite
t = task t: ["preqA", "preqB"]
assert_equal "preqA", t.source
end
end

def test_suggests_valid_rake_task_names
task :test
error = assert_raises(RuntimeError) { Task[:testt] }

assert_match /Don\'t know how to build task \'testt\'/, error.message

if defined?(::DidYouMean::SpellChecker) && defined?(::DidYouMean::Formatter)
assert_match /Did you mean\? test/, error.message
end
end
end