提交 14c89e72 编写于 作者: J Jeremy Kemper

Rails::SubTestTask warns on test failure and moves on. Renamed from TestTaskWithoutDescription.

This makes it easier to add your own tests to the default suite:

  task test: 'test:acceptance'

  namespace :test do
    Rails::SubTestTask.new acceptance: 'test:prepare' do |t|
      t.libs << 'test'
      t.pattern = 'test/acceptance/**/*_test.rb'
    end
  end

Now `rake` runs unit, functional, integration, and acceptance tests.
上级 c1b2642a
require 'rbconfig'
require 'rake/testtask'
# Monkey-patch to silence the description from Rake::TestTask to cut down on rake -T noise
class TestTaskWithoutDescription < Rake::TestTask
# Create the tasks defined by this task lib.
def define
lib_path = @libs.join(File::PATH_SEPARATOR)
task @name do
run_code = ''
RakeFileUtils.verbose(@verbose) do
run_code =
case @loader
when :direct
"-e 'ARGV.each{|f| load f}'"
when :testrb
"-S testrb #{fix}"
when :rake
rake_loader
module Rails
# Don't abort when tests fail; move on the next test task.
# Silence the default description to cut down on `rake -T` noise.
class SubTestTask < Rake::TestTask
# Create the tasks defined by this task lib.
def define
lib_path = @libs.join(File::PATH_SEPARATOR)
task @name do
run_code = ''
RakeFileUtils.verbose(@verbose) do
run_code =
case @loader
when :direct
"-e 'ARGV.each{|f| load f}'"
when :testrb
"-S testrb #{fix}"
when :rake
rake_loader
end
@ruby_opts.unshift( "-I\"#{lib_path}\"" )
@ruby_opts.unshift( "-w" ) if @warning
begin
ruby @ruby_opts.join(" ") +
" \"#{run_code}\" " +
file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
" #{option_list}"
rescue => error
warn "Error running #{@name}: #{error.inspect}"
end
@ruby_opts.unshift( "-I\"#{lib_path}\"" )
@ruby_opts.unshift( "-w" ) if @warning
ruby @ruby_opts.join(" ") +
" \"#{run_code}\" " +
file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
" #{option_list}"
end
end
self
end
self
end
end
......@@ -75,22 +83,7 @@ end
task :default => :test
desc 'Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)'
task :test do
tests_to_run = ENV['TEST'] ? ["test:single"] : %w(test:units test:functionals test:integration)
errors = tests_to_run.collect do |task|
begin
Rake::Task[task].invoke
nil
rescue => e
{ :task => task, :exception => e }
end
end.compact
if errors.any?
puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
abort
end
end
task :test => %w(test:units test:functionals test:integration)
namespace :test do
task :prepare do
......@@ -134,33 +127,33 @@ namespace :test do
t.libs << "test"
end
TestTaskWithoutDescription.new(:units => "test:prepare") do |t|
Rails::SubTestTask.new(:units => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb'
end
TestTaskWithoutDescription.new(:functionals => "test:prepare") do |t|
Rails::SubTestTask.new(:functionals => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/functional/**/*_test.rb'
end
TestTaskWithoutDescription.new(:integration => "test:prepare") do |t|
Rails::SubTestTask.new(:integration => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/integration/**/*_test.rb'
end
TestTaskWithoutDescription.new(:benchmark => 'test:prepare') do |t|
Rails::SubTestTask.new(:benchmark => 'test:prepare') do |t|
t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb'
t.options = '-- --benchmark'
end
TestTaskWithoutDescription.new(:profile => 'test:prepare') do |t|
Rails::SubTestTask.new(:profile => 'test:prepare') do |t|
t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb'
end
TestTaskWithoutDescription.new(:plugins => :environment) do |t|
Rails::SubTestTask.new(:plugins => :environment) do |t|
t.libs << "test"
if ENV['PLUGIN']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册