Skip to content

Commit

Permalink
Use the application's name in error message if a task is not found
Browse files Browse the repository at this point in the history
`Rake.application` can be initialized with a custom name, so use that in
the error message when a task is not found in the index. The default
application name is `rake`.
  • Loading branch information
tmatilai committed Jan 20, 2019
1 parent 9d9b431 commit d28957d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rake/task_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def [](task_name, scopes=nil)
end

def generate_message_for_undefined_task(task_name)
message = "Don't know how to build task '#{task_name}' (See the list of available tasks with `rake --tasks`)"
message = "Don't know how to build task '#{task_name}' "\
"(See the list of available tasks with `#{Rake.application.name} --tasks`)"
message + generate_did_you_mean_suggestions(task_name)
end

Expand Down
10 changes: 10 additions & 0 deletions test/test_rake_task_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def test_index
assert_equal "Don't know how to build task 'bad' (See the list of available tasks with `rake --tasks`)", e.message
end

def test_undefined_task_with_custom_application
Rake.application.init("myrake", nil)

e = assert_raises RuntimeError do
@tm["bad"]
end

assert_equal "Don't know how to build task 'bad' (See the list of available tasks with `myrake --tasks`)", e.message
end

def test_name_lookup
t = @tm.define_task(Rake::Task, :t)
assert_equal t, @tm[:t]
Expand Down

0 comments on commit d28957d

Please sign in to comment.