From 7ec0e9821f9f6a2f312a34ae52533c8409ec72d7 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Tue, 30 Sep 2008 23:30:30 +0200 Subject: [PATCH] Fixed plugin generator so that generated unit tests would subclass ActiveSupport::TestCase, also introduced a helper script to reduce the needed require statements. --- .../components/plugin/plugin_generator.rb | 20 ++++++++++---------- .../components/plugin/templates/Rakefile | 1 + .../components/plugin/templates/test_helper.rb | 3 +++ .../components/plugin/templates/unit_test.rb | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb diff --git a/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb b/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb index 7a61982..3b4e307 100644 --- a/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb +++ b/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb @@ -16,16 +16,16 @@ class PluginGenerator < Rails::Generator::NamedBase m.directory "#{plugin_path}/tasks" m.directory "#{plugin_path}/test" - m.template 'README', "#{plugin_path}/README" - m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE" - m.template 'Rakefile', "#{plugin_path}/Rakefile" - m.template 'init.rb', "#{plugin_path}/init.rb" - m.template 'install.rb', "#{plugin_path}/install.rb" - m.template 'uninstall.rb', "#{plugin_path}/uninstall.rb" - m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb" - m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake" - m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb" - + m.template 'README', "#{plugin_path}/README" + m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE" + m.template 'Rakefile', "#{plugin_path}/Rakefile" + m.template 'init.rb', "#{plugin_path}/init.rb" + m.template 'install.rb', "#{plugin_path}/install.rb" + m.template 'uninstall.rb', "#{plugin_path}/uninstall.rb" + m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb" + m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake" + m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb" + m.template 'test_helper.rb', "#{plugin_path}/test/test_helper.rb" if @with_generator m.directory "#{plugin_path}/generators" m.directory "#{plugin_path}/generators/#{file_name}" diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile b/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile index 1824fb1..85e8ff1 100644 --- a/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile +++ b/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile @@ -8,6 +8,7 @@ task :default => :test desc 'Test the <%= file_name %> plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' + t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = true end diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb b/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb new file mode 100644 index 0000000..cf148b8 --- /dev/null +++ b/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb @@ -0,0 +1,3 @@ +require 'rubygems' +require 'active_support' +require 'active_support/test_case' \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb index 6ede6ef..3e0bc29 100644 --- a/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb @@ -1,6 +1,6 @@ -require 'test/unit' +require 'test_helper' -class <%= class_name %>Test < Test::Unit::TestCase +class <%= class_name %>Test < ActiveSupport::TestCase # Replace this with your real tests. test "the truth" do assert true -- 1.6.0