diff options
Diffstat (limited to 'railties/test/generators/plugin_new_generator_test.rb')
-rw-r--r-- | railties/test/generators/plugin_new_generator_test.rb | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 9183945619..51374e5f3f 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/plugin_new/plugin_new_generator' require 'generators/shared_generator_tests.rb' @@ -28,13 +27,20 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase include SharedGeneratorTests def test_invalid_plugin_name_raises_an_error - content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] } - assert_equal "Invalid plugin name 43-things. Please give a name which does not start with numbers.\n", content + content = capture(:stderr){ run_generator [File.join(destination_root, "things-43")] } + assert_equal "Invalid plugin name things-43. Please give a name which use only alphabetic or numeric or \"_\" characters.\n", content + + content = capture(:stderr){ run_generator [File.join(destination_root, "things4.3")] } + assert_equal "Invalid plugin name things4.3. Please give a name which use only alphabetic or numeric or \"_\" characters.\n", content + + content = capture(:stderr){ run_generator [File.join(destination_root, "43things")] } + assert_equal "Invalid plugin name 43things. Please give a name which does not start with numbers.\n", content end - def test_invalid_plugin_name_is_fixed - run_generator [File.join(destination_root, "things-43")] - assert_file "things-43/lib/things-43.rb", /module Things43/ + def test_camelcase_plugin_name_underscores_filenames + run_generator [File.join(destination_root, "CamelCasedName")] + assert_no_file "CamelCasedName/lib/CamelCasedName.rb" + assert_file "CamelCasedName/lib/camel_cased_name.rb", /module CamelCasedName/ end def test_generating_without_options @@ -205,7 +211,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_creating_gemspec run_generator assert_file "bukkits.gemspec", /s.name\s+= "bukkits"/ - assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*"\]/ + assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*", "MIT-LICENSE", "Rakefile", "README\.rdoc"\]/ assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/ assert_file "bukkits.gemspec", /s.version\s+ = Bukkits::VERSION/ end @@ -230,6 +236,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "test/dummy" end + def test_creating_dummy_application_with_different_name + run_generator [destination_root, "--dummy_path", "spec/fake"] + assert_file "spec/fake" + assert_file "spec/fake/config/application.rb" + assert_no_file "test/dummy" + end + def test_creating_dummy_without_tests_but_with_dummy_path run_generator [destination_root, "--dummy_path", "spec/dummy", "--skip-test-unit"] assert_file "spec/dummy" @@ -237,6 +250,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "test" end + def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path + FileUtils.cd(Rails.root) + run_generator([destination_root, "--dummy_path", "spec/dummy" "--skip-test-unit"]) + assert_file ".gitignore" do |contents| + assert_match(/spec\/dummy/, contents) + end + end + def test_skipping_test_unit run_generator [destination_root, "--skip-test-unit"] assert_no_file "test" @@ -250,6 +271,37 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "bukkits.gemspec" end + def test_creating_plugin_in_app_directory_adds_gemfile_entry + # simulate application existance + gemfile_path = "#{Rails.root}/Gemfile" + Object.const_set('APP_PATH', Rails.root) + FileUtils.touch gemfile_path + + run_generator [destination_root] + + assert_file gemfile_path, /gem 'bukkits', :path => 'tmp\/bukkits'/ + ensure + Object.send(:remove_const, 'APP_PATH') + FileUtils.rm gemfile_path + end + + def test_skipping_gemfile_entry + # simulate application existance + gemfile_path = "#{Rails.root}/Gemfile" + Object.const_set('APP_PATH', Rails.root) + FileUtils.touch gemfile_path + + run_generator [destination_root, "--skip-gemfile-entry"] + + assert_file gemfile_path do |contents| + assert_no_match(/gem 'bukkits', :path => 'tmp\/bukkits'/, contents) + end + ensure + Object.send(:remove_const, 'APP_PATH') + FileUtils.rm gemfile_path + end + + protected def action(*args, &block) |