aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators_test.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2014-06-03 18:22:45 -0500
committerschneems <richard.schneeman@gmail.com>2014-06-04 16:28:43 -0500
commit72f45ba2922771e744d91334b8680b9b51784eec (patch)
tree327247cc8f2868550e02d036a4d822e91d613a4f /railties/test/generators_test.rb
parent3036c4031ab0ce2632d6ac1479ab27cdc4bb4941 (diff)
downloadrails-72f45ba2922771e744d91334b8680b9b51784eec.tar.gz
rails-72f45ba2922771e744d91334b8680b9b51784eec.tar.bz2
rails-72f45ba2922771e744d91334b8680b9b51784eec.zip
Emit suggested generator names when not found
When someone types in a generator command it currently outputs all generators. Instead we can attempt to find a subtle mis-spelling by running all generator names through a levenshtein_distance algorithm provided by rubygems. So now a failure looks like this: ```ruby $ rails generate migratioooons Could not find generator 'migratioooons'. Maybe you meant 'migration' or 'integration_test' or 'generator' Run `rails generate --help` for more options. ``` If the suggestions are bad we leave the user with the hint to run `rails generate --help` to see all commands.
Diffstat (limited to 'railties/test/generators_test.rb')
-rw-r--r--railties/test/generators_test.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 8d6dbf80c2..0b4edafaca 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -24,7 +24,13 @@ class GeneratorsTest < Rails::Generators::TestCase
name = :unknown
output = capture(:stdout){ Rails::Generators.invoke name }
assert_match "Could not find generator '#{name}'", output
- assert_match "scaffold", output
+ assert_match "`rails generate --help`", output
+ end
+
+ def test_generator_suggestions
+ name = :migrationz
+ output = capture(:stdout){ Rails::Generators.invoke name }
+ assert_match "Maybe you meant 'migration'", output
end
def test_help_when_a_generator_with_required_arguments_is_invoked_without_arguments