Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow easy overriding of test framework in 'rake plugin new' generato…

…r, using PluginBuilder
  • Loading branch information...
commit b36fa51a3f56431d8e46c1fff6a6493d3c10607a 1 parent fd1562a
@drogus authored
View
35 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -35,7 +35,7 @@ def test
directory "test"
end
- def test_dummy
+ def generate_test_dummy
invoke Rails::Generators::AppGenerator,
[ File.expand_path(dummy_path, destination_root) ], {}
end
@@ -68,6 +68,27 @@ def script
end
chmod "script", 0755, :verbose => false
end
+
+ def rakefile_test_tasks
+ <<-RUBY
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+ RUBY
+ end
+
+ def dummy_path
+ "#{test_path}/dummy"
+ end
+
+ def test_path
+ "test"
+ end
end
module Generators
@@ -141,7 +162,7 @@ def create_test_files
say_step "Vendoring Rails application at test/dummy"
def create_test_dummy_files
- build(:test_dummy)
+ build(:generate_test_dummy)
end
say_step "Configuring Rails application"
@@ -192,10 +213,6 @@ def valid_const?
end
end
- def dummy_path
- "test/dummy"
- end
-
def application_definition
@application_definition ||= begin
unless options[:pretend]
@@ -209,6 +226,12 @@ def application_definition
def get_builder_class
defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
end
+
+ [:test_path, :dummy_path, :rakefile_test_tasks].each do |name|
+ define_method name do
+ builder.send(name) if builder.respond_to?(name)
+ end
+ end
end
end
end
View
11 railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
@@ -10,16 +10,9 @@ require 'rake'
require 'rake/rdoctask'
require 'rake/gempackagetask'
-require 'rake/testtask'
+<%= rakefile_test_tasks %>
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = false
-end
-
-task :default => :test
+task :default => :<%= test_path %>
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
View
2  railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
@@ -2,4 +2,4 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_PATH = File.expand_path('../..', __FILE__)
-load File.expand_path('../../test/dummy/script/rails', __FILE__)
+load File.expand_path('../../<%= test_path %>/dummy/script/rails', __FILE__)
View
13 railties/test/fixtures/lib/plugin_builders/spec_builder.rb
@@ -0,0 +1,13 @@
+class PluginBuilder < Rails::PluginBuilder
+ def test
+ create_file "spec/spec_helper.rb"
+ end
+
+ def test_path
+ "spec"
+ end
+
+ def rakefile_test_tasks
+ "# spec tasks in rakefile"
+ end
+end
View
10 railties/test/generators/plugin_new_generator_test.rb
@@ -217,6 +217,16 @@ def test_builder_option_with_http
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)
Please sign in to comment.
Something went wrong with that request. Please try again.