diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-04-30 13:08:28 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-04-30 13:48:06 -0700 |
commit | 785493ffed41abcca0686bf05b0a0157e0844d47 (patch) | |
tree | 07ede62e2e5634814e161671d20cf18915ef1141 /railties/test | |
parent | 0761d1b0f7e89d49fe8cd6ab7eed3f084bd56fbd (diff) | |
download | rails-785493ffed41abcca0686bf05b0a0157e0844d47.tar.gz rails-785493ffed41abcca0686bf05b0a0157e0844d47.tar.bz2 rails-785493ffed41abcca0686bf05b0a0157e0844d47.zip |
Provide a mechanism for overriding the entire generator via a class that handles the individual elements of generating a new Rails application
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 134 |
1 files changed, 96 insertions, 38 deletions
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 1e5aa156ce..1a93867013 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -2,6 +2,40 @@ require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' +DEFAULT_APP_FILES = %w( + .gitignore + Gemfile + Rakefile + config.ru + app/controllers + app/helpers + app/models + app/views/layouts + config/environments + config/initializers + config/locales + db + doc + lib + lib/tasks + log + public/images + public/javascripts + public/stylesheets + script/rails + test/fixtures + test/functional + test/integration + test/performance + test/unit + vendor + vendor/plugins + tmp/sessions + tmp/sockets + tmp/cache + tmp/pids +) + class AppGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments [destination_root] @@ -20,39 +54,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_application_skeleton_is_created run_generator - %w( - .gitignore - Gemfile - Rakefile - config.ru - app/controllers - app/helpers - app/models - app/views/layouts - config/environments - config/initializers - config/locales - db - doc - lib - lib/tasks - log - public/images - public/javascripts - public/stylesheets - script/rails - test/fixtures - test/functional - test/integration - test/performance - test/unit - vendor - vendor/plugins - tmp/sessions - tmp/sockets - tmp/cache - tmp/pids - ).each{ |path| assert_file path } + DEFAULT_APP_FILES.each{ |path| assert_file path } end def test_application_controller_and_layout_files @@ -66,7 +68,7 @@ class AppGeneratorTest < Rails::Generators::TestCase content = capture(:stderr){ run_generator(["--skip-activerecord", destination_root]) } assert_equal "Options should be given after the application name. For details run: rails --help\n", content end - + def test_name_collision_raises_an_error content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] } assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content @@ -197,10 +199,66 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/ end - protected +protected - def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } - end + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end end + +class CustomAppGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + tests Rails::Generators::AppGenerator + + arguments [destination_root] + + def setup + super + Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) + @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') + end + + def teardown + super + Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) + Object.class_eval { remove_const :AppBuilder if const_defined?(:AppBuilder) } + end + + def test_builder_option_with_empty_app_builder + FileUtils.cd(Rails.root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/empty_builder.rb"]) + DEFAULT_APP_FILES.each{ |path| assert_no_file path } + end + + def test_builder_option_with_simple_app_builder + FileUtils.cd(Rails.root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/simple_builder.rb"]) + (DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path } + assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] + end + + def test_builder_option_with_tweak_app_builder + FileUtils.cd(Rails.root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"]) + DEFAULT_APP_FILES.each{ |path| assert_file path } + assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] + end + + def test_builder_option_with_http + path = "http://gist.github.com/103208.txt" + template = "class AppBuilder; end" + template.instance_eval "def read; self; end" # Make the string respond to read + + generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) + capture(:stdout) { generator.invoke } + + DEFAULT_APP_FILES.each{ |path| assert_no_file path } + end + +protected + + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end +end
\ No newline at end of file |