aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/generator_generator_test.rb
blob: dcfeaaa8e0d5d324dfe1fbbedd465ce5e702b687 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'generators/generators_test_helper'
require 'rails/generators/rails/generator/generator_generator'

class GeneratorGeneratorTest < Rails::Generators::TestCase
  include GeneratorsTestHelper
  arguments %w(awesome)

  def test_generator_skeleton_is_created
    run_generator

    %w(
      lib/generators/awesome
      lib/generators/awesome/USAGE
      lib/generators/awesome/templates
    ).each{ |path| assert_file path }

    assert_file "lib/generators/awesome/awesome_generator.rb",
                /class AwesomeGenerator < Rails::Generators::NamedBase/
    assert_file "test/lib/generators/awesome_generator_test.rb",
               /class AwesomeGeneratorTest < Rails::Generators::TestCase/,
               /require 'generators\/awesome\/awesome_generator'/
  end

  def test_namespaced_generator_skeleton
    run_generator ["rails/awesome"]

    %w(
      lib/generators/rails/awesome
      lib/generators/rails/awesome/USAGE
      lib/generators/rails/awesome/templates
    ).each{ |path| assert_file path }

    assert_file "lib/generators/rails/awesome/awesome_generator.rb",
                /class Rails::AwesomeGenerator < Rails::Generators::NamedBase/
    assert_file "test/lib/generators/rails/awesome_generator_test.rb",
               /class Rails::AwesomeGeneratorTest < Rails::Generators::TestCase/,
               /require 'generators\/rails\/awesome\/awesome_generator'/
  end

  def test_generator_skeleton_is_created_without_file_name_namespace
    run_generator ["awesome", "--namespace", "false"]

    %w(
      lib/generators/
      lib/generators/USAGE
      lib/generators/templates
    ).each{ |path| assert_file path }

    assert_file "lib/generators/awesome_generator.rb",
                /class AwesomeGenerator < Rails::Generators::NamedBase/
    assert_file "test/lib/generators/awesome_generator_test.rb",
               /class AwesomeGeneratorTest < Rails::Generators::TestCase/,
               /require 'generators\/awesome_generator'/
  end

  def test_namespaced_generator_skeleton_without_file_name_namespace
    run_generator ["rails/awesome", "--namespace", "false"]

    %w(
      lib/generators/rails
      lib/generators/rails/USAGE
      lib/generators/rails/templates
    ).each{ |path| assert_file path }

    assert_file "lib/generators/rails/awesome_generator.rb",
                /class Rails::AwesomeGenerator < Rails::Generators::NamedBase/
    assert_file "test/lib/generators/rails/awesome_generator_test.rb",
               /class Rails::AwesomeGeneratorTest < Rails::Generators::TestCase/,
               /require 'generators\/rails\/awesome_generator'/
  end
end