From cfcea1d53ae5ce38a7cbeb41e05958dc009988b0 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 15 Oct 2010 17:46:31 +0300 Subject: Added 'rails plugin new' generator which generates gem plugin skeleton. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This command is based on enginex gem by José Valim. It generates gem structure and ads dummy application into test/dummy. This can be used to start developing any kind of extension for rails 3. --- .../test/generators/plugin_new_generator_test.rb | 179 +++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 railties/test/generators/plugin_new_generator_test.rb (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb new file mode 100644 index 0000000000..3c38dffce2 --- /dev/null +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -0,0 +1,179 @@ +require 'abstract_unit' +require 'generators/generators_test_helper' +require 'rails/generators/rails/plugin_new/plugin_new_generator' + +DEFAULT_PLUGIN_FILES = %w( + .gitignore + Gemfile + Rakefile + bukkits.gemspec + MIT-LICENSE + lib + lib/bukkits.rb + script/rails + test/bukkits_test.rb + test/integration/navigation_test.rb + test/support/integration_case.rb + test/test_helper.rb + test/dummy +) + + +class PluginNewGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + destination File.join(Rails.root, "tmp/bukkits") + arguments [destination_root] + + def setup + Rails.application = TestApp::Application + super + @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') + + Kernel::silence_warnings do + Thor::Base.shell.send(:attr_accessor, :always_force) + @shell = Thor::Base.shell.new + @shell.send(:always_force=, true) + end + end + + def teardown + super + Rails.application = TestApp::Application.instance + end + + def test_plugin_skeleton_is_created + run_generator + + DEFAULT_PLUGIN_FILES.each{ |path| assert_file path } + end + + def test_plugin_new_generate_pretend + run_generator ["testapp", "--pretend"] + + DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } + end + + def test_options_before_plugin_name_raises_an_error + content = capture(:stderr){ run_generator(["--pretend", destination_root]) } + assert_equal "Options should be given after plugin name. For details run: rails plugin --help\n", content + end + + def test_name_collision_raises_an_error + reserved_words = %w[application destroy plugin runner test] + reserved_words.each do |reserved| + content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] } + assert_equal "Invalid plugin name #{reserved}. Please give a name which does not match one of the reserved rails words.\n", content + end + end + + 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 + end + + def test_plugin_name_raises_an_error_if_name_already_used_constant + %w{ String Hash Class Module Set Symbol }.each do |ruby_class| + content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] } + assert_equal "Invalid plugin name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another application name.\n", content + end + 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/ + end + + def test_shebang_is_added_to_rails_file + run_generator [destination_root, "--ruby", "foo/bar/baz"] + assert_file "script/rails", /#!foo\/bar\/baz/ + end + + def test_shebang_when_is_the_same_as_default_use_env + run_generator [destination_root, "--ruby", Thor::Util.ruby_command] + assert_file "script/rails", /#!\/usr\/bin\/env/ + end + + def test_generating_test_files + run_generator + assert_file "test/test_helper.rb" + assert_directory "test/support/" + assert_directory "test/integration/" + + assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ + assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/ + assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/ + end + +protected + + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end + +end + +class CustomPluginGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + tests Rails::Generators::PluginNewGenerator + + destination File.join(Rails.root, "tmp/bukkits") + arguments [destination_root] + + def setup + Rails.application = TestApp::Application + super + @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') + end + + def teardown + super + Object.class_eval { remove_const :PluginBuilder if const_defined?(:PluginBuilder) } + Rails.application = TestApp::Application.instance + end + + def test_builder_option_with_empty_app_builder + FileUtils.cd(destination_root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/empty_builder.rb"]) + DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } + end + + def test_builder_option_with_simple_plugin_builder + FileUtils.cd(destination_root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/simple_builder.rb"]) + (DEFAULT_PLUGIN_FILES - ['.gitignore']).each{ |path| assert_no_file path } + assert_file ".gitignore", "foobar" + end + + def test_builder_option_with_relative_path + here = File.expand_path(File.dirname(__FILE__)) + FileUtils.cd(here) + run_generator([destination_root, "-b", "../fixtures/lib/plugin_builders/simple_builder.rb"]) + FileUtils.cd(destination_root) + (DEFAULT_PLUGIN_FILES - ['.gitignore']).each{ |path| assert_no_file path } + assert_file ".gitignore", "foobar" + end + + def test_builder_option_with_tweak_plugin_builder + FileUtils.cd(destination_root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/tweak_builder.rb"]) + DEFAULT_PLUGIN_FILES.each{ |path| assert_file path } + assert_file ".gitignore", "foobar" + end + + def test_builder_option_with_http + path = "http://gist.github.com/103208.txt" + template = "class PluginBuilder; 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_all } + + DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } + end + +protected + + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end +end -- cgit v1.2.3 From b8a0fabe184f6c8f926f7869341ca40b6395606a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 20 Oct 2010 00:47:13 +0200 Subject: Ensure that options for plugin new generator are not passed to application generator --- railties/test/generators/plugin_new_generator_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 3c38dffce2..fa00e75132 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -104,6 +104,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/ end + def test_ensure_that_plugin_options_are_not_passed_app_generator + output = run_generator [destination_root, "--skip_gemfile"] + assert_no_file "Gemfile" + assert_match /STEP 2.*create Gemfile/m, output + end + protected def action(*args, &block) -- cgit v1.2.3 From bcd414fd10a0e401cfb1de95cc9b2940b1df0ff6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 20 Oct 2010 01:05:34 +0200 Subject: Add support for templates for rails plugin new --- .../test/generators/plugin_new_generator_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index fa00e75132..f3672cb6f1 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -110,6 +110,26 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match /STEP 2.*create Gemfile/m, output end + def test_template_from_dir_pwd + FileUtils.cd(Rails.root) + assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) + end + + def test_template_raises_an_error_with_invalid_path + content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) } + assert_match /The template \[.*\] could not be loaded/, content + assert_match /non\/existant\/path/, content + end + + def test_template_is_executed_when_supplied + path = "http://gist.github.com/103208.txt" + template = %{ say "It works!" } + template.instance_eval "def read; self; end" # Make the string respond to read + + generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) + assert_match /It works!/, silence(:stdout){ generator.invoke_all } + end + protected def action(*args, &block) -- cgit v1.2.3 From e51e9e2db0359355feef71e735a1f9cb764ec929 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 20 Oct 2010 07:59:28 +0200 Subject: Add --dev and --edge options to rails plugin new --- railties/test/generators/plugin_new_generator_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index f3672cb6f1..638ff8dce5 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -130,6 +130,19 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match /It works!/, silence(:stdout){ generator.invoke_all } end + def test_dev_option + generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install") + silence(:stdout){ generator.invoke_all } + rails_path = File.expand_path('../../..', Rails.root) + assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/ + end + + def test_edge_option + generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install") + silence(:stdout){ generator.invoke_all } + assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/ + end + protected def action(*args, &block) -- cgit v1.2.3 From 59d52229f9ddd55a1cf0674c774a8aeb68300ccf Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 20 Oct 2010 20:45:21 +0200 Subject: Change // style regexp to %r{}, to not confuse editors code highlighting --- railties/test/generators/plugin_new_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 638ff8dce5..8f230525bc 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -140,7 +140,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_edge_option generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install") silence(:stdout){ generator.invoke_all } - assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/ + assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} end protected -- cgit v1.2.3 From fd1562af8c662fee8a44d244eaed3350ce10e7da Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 20 Oct 2010 21:21:37 +0200 Subject: Ensure that tests run properly --- railties/test/generators/plugin_new_generator_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 8f230525bc..0d88d36971 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -143,6 +143,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} end + def test_ensure_that_tests_works + run_generator + FileUtils.cd destination_root + `bundle install` + assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test` + end + protected def action(*args, &block) -- cgit v1.2.3 From b36fa51a3f56431d8e46c1fff6a6493d3c10607a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 20 Oct 2010 21:21:14 +0200 Subject: Allow easy overriding of test framework in 'rake plugin new' generator, using PluginBuilder --- railties/test/generators/plugin_new_generator_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 0d88d36971..a7177914e1 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -217,6 +217,16 @@ class CustomPluginGeneratorTest < Rails::Generators::TestCase DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } end + def test_overriding_test_framework + FileUtils.cd(destination_root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/spec_builder.rb"]) + assert_file 'spec/spec_helper.rb' + assert_file 'Rakefile', /task :default => :spec/ + assert_file 'Rakefile', /# spec tasks in rakefile/ + assert_file 'spec/dummy' + assert_file 'script/rails', %r{spec/dummy} + end + protected def action(*args, &block) -- cgit v1.2.3 From ae1debd442113ed9476e776fe27cd95730896b59 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 21 Oct 2010 00:55:08 +0200 Subject: Make tests for app and plugin generators more DRY --- .../test/generators/plugin_new_generator_test.rb | 153 +++------------------ 1 file changed, 16 insertions(+), 137 deletions(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index a7177914e1..e8a9c8ff51 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/plugin_new/plugin_new_generator' +require 'generators/shared_generator_tests.rb' DEFAULT_PLUGIN_FILES = %w( .gitignore @@ -23,47 +24,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper destination File.join(Rails.root, "tmp/bukkits") arguments [destination_root] + include SharedGeneratorTests - def setup - Rails.application = TestApp::Application - super - @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') - - Kernel::silence_warnings do - Thor::Base.shell.send(:attr_accessor, :always_force) - @shell = Thor::Base.shell.new - @shell.send(:always_force=, true) - end - end - - def teardown - super - Rails.application = TestApp::Application.instance - end - - def test_plugin_skeleton_is_created - run_generator - - DEFAULT_PLUGIN_FILES.each{ |path| assert_file path } - end - - def test_plugin_new_generate_pretend - run_generator ["testapp", "--pretend"] - - DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } - end - - def test_options_before_plugin_name_raises_an_error - content = capture(:stderr){ run_generator(["--pretend", destination_root]) } - assert_equal "Options should be given after plugin name. For details run: rails plugin --help\n", content - end - - def test_name_collision_raises_an_error - reserved_words = %w[application destroy plugin runner test] - reserved_words.each do |reserved| - content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] } - assert_equal "Invalid plugin name #{reserved}. Please give a name which does not match one of the reserved rails words.\n", content - end + def default_files + ::DEFAULT_PLUGIN_FILES end def test_invalid_plugin_name_raises_an_error @@ -71,28 +35,11 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_equal "Invalid plugin name 43-things. Please give a name which does not start with numbers.\n", content end - def test_plugin_name_raises_an_error_if_name_already_used_constant - %w{ String Hash Class Module Set Symbol }.each do |ruby_class| - content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] } - assert_equal "Invalid plugin name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another application name.\n", content - end - 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/ end - def test_shebang_is_added_to_rails_file - run_generator [destination_root, "--ruby", "foo/bar/baz"] - assert_file "script/rails", /#!foo\/bar\/baz/ - end - - def test_shebang_when_is_the_same_as_default_use_env - run_generator [destination_root, "--ruby", Thor::Util.ruby_command] - assert_file "script/rails", /#!\/usr\/bin\/env/ - end - def test_generating_test_files run_generator assert_file "test/test_helper.rb" @@ -115,34 +62,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) end - def test_template_raises_an_error_with_invalid_path - content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) } - assert_match /The template \[.*\] could not be loaded/, content - assert_match /non\/existant\/path/, content - end - - def test_template_is_executed_when_supplied - path = "http://gist.github.com/103208.txt" - template = %{ say "It works!" } - template.instance_eval "def read; self; end" # Make the string respond to read - - generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - assert_match /It works!/, silence(:stdout){ generator.invoke_all } - end - - def test_dev_option - generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke_all } - rails_path = File.expand_path('../../..', Rails.root) - assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/ - end - - def test_edge_option - generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke_all } - assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} - end - def test_ensure_that_tests_works run_generator FileUtils.cd destination_root @@ -164,58 +83,7 @@ class CustomPluginGeneratorTest < Rails::Generators::TestCase destination File.join(Rails.root, "tmp/bukkits") arguments [destination_root] - - def setup - Rails.application = TestApp::Application - super - @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') - end - - def teardown - super - Object.class_eval { remove_const :PluginBuilder if const_defined?(:PluginBuilder) } - Rails.application = TestApp::Application.instance - end - - def test_builder_option_with_empty_app_builder - FileUtils.cd(destination_root) - run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/empty_builder.rb"]) - DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } - end - - def test_builder_option_with_simple_plugin_builder - FileUtils.cd(destination_root) - run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/simple_builder.rb"]) - (DEFAULT_PLUGIN_FILES - ['.gitignore']).each{ |path| assert_no_file path } - assert_file ".gitignore", "foobar" - end - - def test_builder_option_with_relative_path - here = File.expand_path(File.dirname(__FILE__)) - FileUtils.cd(here) - run_generator([destination_root, "-b", "../fixtures/lib/plugin_builders/simple_builder.rb"]) - FileUtils.cd(destination_root) - (DEFAULT_PLUGIN_FILES - ['.gitignore']).each{ |path| assert_no_file path } - assert_file ".gitignore", "foobar" - end - - def test_builder_option_with_tweak_plugin_builder - FileUtils.cd(destination_root) - run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/tweak_builder.rb"]) - DEFAULT_PLUGIN_FILES.each{ |path| assert_file path } - assert_file ".gitignore", "foobar" - end - - def test_builder_option_with_http - path = "http://gist.github.com/103208.txt" - template = "class PluginBuilder; 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_all } - - DEFAULT_PLUGIN_FILES.each{ |path| assert_no_file path } - end + include SharedCustomGeneratorTests def test_overriding_test_framework FileUtils.cd(destination_root) @@ -228,6 +96,17 @@ class CustomPluginGeneratorTest < Rails::Generators::TestCase end protected + def default_files + ::DEFAULT_PLUGIN_FILES + end + + def builder_class + :PluginBuilder + end + + def builders_dir + "plugin_builders" + end def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } -- cgit v1.2.3 From 68295bc69349fc4fd4f8fa2023cf369b70039848 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 23 Oct 2010 18:24:04 +0200 Subject: Remove integration tests and ActionModel/ActiveRecord calls from 'rake plugin new' generator, it shouldn't be available as default option --- railties/test/generators/plugin_new_generator_test.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index e8a9c8ff51..2049d31b18 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -13,8 +13,6 @@ DEFAULT_PLUGIN_FILES = %w( lib/bukkits.rb script/rails test/bukkits_test.rb - test/integration/navigation_test.rb - test/support/integration_case.rb test/test_helper.rb test/dummy ) @@ -43,12 +41,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_generating_test_files run_generator assert_file "test/test_helper.rb" - assert_directory "test/support/" - assert_directory "test/integration/" assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ - assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/ - assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/ end def test_ensure_that_plugin_options_are_not_passed_app_generator @@ -66,7 +60,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator FileUtils.cd destination_root `bundle install` - assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test` + assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test` end protected -- cgit v1.2.3 From fdbd9df21e0063da4b34346c54fbe21ac9583ca6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 23 Oct 2010 20:56:02 +0200 Subject: No need for say_step in 'plugin new' generator --- railties/test/generators/plugin_new_generator_test.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 2049d31b18..bf395749e5 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -45,10 +45,9 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ end - def test_ensure_that_plugin_options_are_not_passed_app_generator - output = run_generator [destination_root, "--skip_gemfile"] - assert_no_file "Gemfile" - assert_match /STEP 2.*create Gemfile/m, output + def test_ensure_that_plugin_options_are_not_passed_to_app_generator + FileUtils.cd(Rails.root) + assert_no_match /It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]) end def test_template_from_dir_pwd -- cgit v1.2.3 From 671d1469c6f70abb7cbd373bb37f18268ed7069c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 26 Oct 2010 22:22:15 +0200 Subject: Add --full option to 'plugin new' generator, which generates rails engine --- .../test/generators/plugin_new_generator_test.rb | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index bf395749e5..f833411e3a 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -41,15 +41,28 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_generating_test_files run_generator assert_file "test/test_helper.rb" - assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ end + def test_generating_test_files_in_full_mode + run_generator [destination_root, "--full"] + assert_directory "test/support/" + assert_directory "test/integration/" + + assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/ + assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/ + end + def test_ensure_that_plugin_options_are_not_passed_to_app_generator FileUtils.cd(Rails.root) assert_no_match /It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]) end + def test_ensure_that_skip_active_record_option_is_passed_to_app_generator + run_generator [destination_root, "--skip_active_record"] + assert_no_file "test/dummy/config/database.yml" + end + def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) @@ -62,6 +75,19 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test` end + def test_ensure_that_tests_works_in_full_mode + run_generator [destination_root, "--full"] + FileUtils.cd destination_root + `bundle install` + assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test` + end + + def test_creating_engine_in_full_mode + run_generator [destination_root, "--full"] + assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/ + assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ + end + protected def action(*args, &block) -- cgit v1.2.3 From 46fdb3197d270551da260cfed3dea7928dd15b0f Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 27 Oct 2010 00:16:57 +0200 Subject: Pass more options to test/dummy in 'plugin new' generator --- railties/test/generators/plugin_new_generator_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index f833411e3a..53e1dd6708 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -63,6 +63,21 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "test/dummy/config/database.yml" end + def test_ensure_that_database_option_is_passed_to_app_generator + run_generator [destination_root, "--database", "postgresql"] + assert_file "test/dummy/config/database.yml", /postgres/ + end + + def test_ensure_that_javascript_option_is_passed_to_app_generator + run_generator [destination_root, "--javascript", "jquery"] + assert_file "test/dummy/public/javascripts/jquery.js" + end + + def test_ensure_that_skip_javascript_option_is_passed_to_app_generator + run_generator [destination_root, "--skip_javascript"] + assert_no_file "test/dummy/public/javascripts/prototype.js" + end + def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) -- cgit v1.2.3 From 489b279fc499f135df48556554739c19d316df0a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 28 Oct 2010 03:00:42 +0200 Subject: Don't be verbose while creating dummy application in plugin new generator --- railties/test/generators/plugin_new_generator_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 53e1dd6708..985ef088e5 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -103,6 +103,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ end + def test_being_quiet_while_creating_dummy_application + assert_no_match /create\s+config\/application.rb/, run_generator + end + protected def action(*args, &block) -- cgit v1.2.3 From 57fae9b2c7d193ec16baf38a8797588fb466db49 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 14:05:11 +0100 Subject: Use rails integration tests by default in 'plugin new' generator --- railties/test/generators/plugin_new_generator_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 985ef088e5..aebd954215 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -46,11 +46,9 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_generating_test_files_in_full_mode run_generator [destination_root, "--full"] - assert_directory "test/support/" assert_directory "test/integration/" - assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/ - assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/ + assert_file "test/integration/navigation_test.rb", /ActionDispatch::IntegrationTest/ end def test_ensure_that_plugin_options_are_not_passed_to_app_generator -- cgit v1.2.3 From b6497d3b5a84ca5e7e15700419ddf44c096c57a2 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 14:07:58 +0100 Subject: Skip active record properly in 'plugin new' generator --- railties/test/generators/plugin_new_generator_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index aebd954215..20c0d0a9bf 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -59,6 +59,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_ensure_that_skip_active_record_option_is_passed_to_app_generator run_generator [destination_root, "--skip_active_record"] assert_no_file "test/dummy/config/database.yml" + assert_no_match /ActiveRecord/, File.read(File.join(destination_root, "test/test_helper.rb")) end def test_ensure_that_database_option_is_passed_to_app_generator -- cgit v1.2.3 From 2133495b8cdcb40a68a03aa786c4353031abe49e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 14:23:45 +0100 Subject: Properly handle other databases in 'plugin new' generator --- railties/test/generators/plugin_new_generator_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 20c0d0a9bf..6b7095ba78 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -56,6 +56,23 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_match /It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]) end + def test_database_entry_is_assed_by_default_in_full_mode + run_generator([destination_root, "--full"]) + assert_file "test/dummy/config/database.yml", /sqlite/ + assert_file "Gemfile", /^gem\s+["']sqlite3-ruby["'],\s+:require\s+=>\s+["']sqlite3["']$/ + end + + def test_config_another_database + run_generator([destination_root, "-d", "mysql", "--full"]) + assert_file "test/dummy/config/database.yml", /mysql/ + assert_file "Gemfile", /^gem\s+["']mysql2["']$/ + end + + def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given + run_generator [destination_root, "--skip-active-record"] + assert_file "test/dummy/config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ + end + def test_ensure_that_skip_active_record_option_is_passed_to_app_generator run_generator [destination_root, "--skip_active_record"] assert_no_file "test/dummy/config/database.yml" -- cgit v1.2.3 From f9e33fc09a6731ad56ff8cfe24b49532ed65039c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 15:13:10 +0100 Subject: create_dummy_app method that allows to easily create dummy application from template --- railties/test/generators/plugin_new_generator_test.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 6b7095ba78..f7f4f0261f 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -56,6 +56,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_match /It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]) end + def test_ensure_that_test_dummy_can_be_generated_from_a_template + FileUtils.cd(Rails.root) + run_generator([destination_root, "-m", "lib/create_test_dummy_template.rb", "--skip-test-unit"]) + assert_file "spec/dummy" + assert_no_file "test" + end + def test_database_entry_is_assed_by_default_in_full_mode run_generator([destination_root, "--full"]) assert_file "test/dummy/config/database.yml", /sqlite/ @@ -143,9 +150,9 @@ class CustomPluginGeneratorTest < Rails::Generators::TestCase FileUtils.cd(destination_root) run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/spec_builder.rb"]) assert_file 'spec/spec_helper.rb' + assert_file 'spec/dummy' assert_file 'Rakefile', /task :default => :spec/ assert_file 'Rakefile', /# spec tasks in rakefile/ - assert_file 'spec/dummy' assert_file 'script/rails', %r{spec/dummy} end -- cgit v1.2.3 From c159b501b0743928bda6a9d0609c263e50691676 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 15:44:07 +0100 Subject: Add example rake task to 'plugin new' generator --- railties/test/generators/plugin_new_generator_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index f7f4f0261f..c66b0024e5 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -11,6 +11,7 @@ DEFAULT_PLUGIN_FILES = %w( MIT-LICENSE lib lib/bukkits.rb + lib/tasks/bukkits_tasks.rake script/rails test/bukkits_test.rb test/test_helper.rb -- cgit v1.2.3 From cbe391b517f55caad8cbefa6f864289d76fab653 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 16:34:07 +0100 Subject: Add --mountable option to 'plugin new' generator which generates full mountable application (engine) --- railties/test/generators/plugin_new_generator_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index c66b0024e5..a59013b061 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -131,6 +131,15 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_match /create\s+config\/application.rb/, run_generator end + def test_create_mountable_application_with_mountable_option + run_generator [destination_root, "--mountable"] + assert_file "config/routes.rb", /Bukkits::Engine.routes.draw do/ + assert_file "lib/bukkits/engine.rb", /isolate_namespace Bukkits/ + assert_file "test/dummy/config/routes.rb", /mount Bukkits::Engine => "\/bukkits"/ + assert_file "app/controllers/bukkits/application_controller.rb", /module Bukkits\n class ApplicationController < ActiveController::Base/ + assert_file "app/helpers/bukkits/application_helper.rb", /module Bukkits\n module ApplicationHelper/ + end + protected def action(*args, &block) -- cgit v1.2.3 From cc135e3b6df1785852de2470b4b93559c88c891e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 8 Nov 2010 22:43:51 +0100 Subject: Allow to set dummy application path through options --- railties/test/generators/plugin_new_generator_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test/generators/plugin_new_generator_test.rb') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index a59013b061..8dc5ca90ba 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -140,6 +140,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "app/helpers/bukkits/application_helper.rb", /module Bukkits\n module ApplicationHelper/ end + def test_passing_dummy_path_as_a_parameter + run_generator [destination_root, "--dummy_path", "spec/dummy"] + assert_file "spec/dummy" + assert_file "spec/dummy/config/application.rb" + assert_no_file "test/dummy" + end + protected def action(*args, &block) -- cgit v1.2.3