Skip to content

Commit

Permalink
Rails::SubTestTask warns on test failure and moves on. Renamed from T…
Browse files Browse the repository at this point in the history
…estTaskWithoutDescription.

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.
  • Loading branch information
jeremy committed Dec 21, 2011
1 parent c1b2642 commit 14c89e7
Showing 1 changed file with 38 additions and 45 deletions.
83 changes: 38 additions & 45 deletions railties/lib/rails/test_unit/testing.rake
@@ -1,32 +1,40 @@
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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 14c89e7

Please sign in to comment.