From d28957d64ae88823200049f8ae3667eb631bdfcc Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Mon, 21 Jan 2019 00:40:35 +0200 Subject: [PATCH] Use the application's name in error message if a task is not found `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`. --- lib/rake/task_manager.rb | 3 ++- test/test_rake_task_manager.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/rake/task_manager.rb b/lib/rake/task_manager.rb index d503a3044..1991088fa 100644 --- a/lib/rake/task_manager.rb +++ b/lib/rake/task_manager.rb @@ -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 diff --git a/test/test_rake_task_manager.rb b/test/test_rake_task_manager.rb index 7d8c40902..88937c604 100644 --- a/test/test_rake_task_manager.rb +++ b/test/test_rake_task_manager.rb @@ -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]