From 72f45ba2922771e744d91334b8680b9b51784eec Mon Sep 17 00:00:00 2001
From: schneems <richard.schneeman@gmail.com>
Date: Tue, 3 Jun 2014 18:22:45 -0500
Subject: 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.
---
 railties/test/generators_test.rb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

(limited to 'railties/test')

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
-- 
cgit v1.2.3