aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2018-12-29 18:57:55 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2018-12-29 18:57:55 +0900
commitfb173b66138adf1d6940aca3af76d3c62307441d (patch)
tree4c2075d68445f103718cfcf34c7c89a603ec4bba /railties
parenta4fe5c5b6606f5b320222069f076c73a2eb3d12e (diff)
downloadrails-fb173b66138adf1d6940aca3af76d3c62307441d.tar.gz
rails-fb173b66138adf1d6940aca3af76d3c62307441d.tar.bz2
rails-fb173b66138adf1d6940aca3af76d3c62307441d.zip
Do not show suggestion message when not exist suggestion
**before** ``` $ ./bin/rails g g Could not find generator 'g'. Maybe you meant nil? Run `rails generate --help` for more options. ``` **after** ``` $ ./bin/rails g g Could not find generator 'g'. Run `rails generate --help` for more options. ```
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands/server/server_command.rb3
-rw-r--r--railties/lib/rails/generators.rb4
-rw-r--r--railties/test/commands/server_test.rb6
-rw-r--r--railties/test/generators_test.rb1
4 files changed, 12 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index 70789e0303..6c4cc3cb86 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -302,9 +302,10 @@ module Rails
MSG
else
suggestion = Rails::Command::Spellchecker.suggest(server, from: RACK_SERVERS)
+ suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
<<~MSG
- Could not find server "#{server}". Maybe you meant #{suggestion.inspect}?
+ Could not find server "#{server}". #{suggestion_msg}
Run `rails server --help` for more options.
MSG
end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 5e8cebc50a..caf8a33c3c 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -272,8 +272,10 @@ module Rails
else
options = sorted_groups.flat_map(&:last)
suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
+ suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
+
puts <<~MSG
- Could not find generator '#{namespace}'. Maybe you meant #{suggestion.inspect}?
+ Could not find generator '#{namespace}'. #{suggestion_msg}
Run `rails generate --help` for more options.
MSG
end
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index fbdd3f3ebb..25b89ecbd8 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -32,6 +32,12 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
assert_match(/Could not find server "tin". Maybe you meant "thin"?/, run_command("--using", "tin"))
end
+ def test_using_server_mistype_without_suggestion
+ output = run_command("--using", "t")
+ assert_match(/Could not find server "t"/, output)
+ assert_no_match(/Maybe you meant/, output)
+ end
+
def test_using_positional_argument_deprecation
assert_match(/DEPRECATION WARNING/, run_command("tin"))
end
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index f98c1f78f7..abdc04a8d3 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -28,6 +28,7 @@ class GeneratorsTest < Rails::Generators::TestCase
output = capture(:stdout) { Rails::Generators.invoke name }
assert_match "Could not find generator '#{name}'", output
assert_match "`rails generate --help`", output
+ assert_no_match "Maybe you meant", output
end
def test_generator_suggestions