Skip to content
This repository
Browse code

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

…estTaskWithoutDescription.

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

  namespace :test do
    task run: 'test:acceptance'

    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...
commit e85484814c9de25a09b468810b6c8c6c2109c90f 1 parent efb75f7
Jeremy Kemper jeremy authored

Showing 1 changed file with 40 additions and 43 deletions. Show diff stats Hide diff stats

  1. +40 43 railties/lib/rails/test_unit/testing.rake
83 railties/lib/rails/test_unit/testing.rake
... ... @@ -1,32 +1,40 @@
1 1 require 'rbconfig'
2 2 require 'rake/testtask'
3 3
4   -# Monkey-patch to silence the description from Rake::TestTask to cut down on rake -T noise
5   -class TestTaskWithoutDescription < Rake::TestTask
6   - # Create the tasks defined by this task lib.
7   - def define
8   - lib_path = @libs.join(File::PATH_SEPARATOR)
9   - task @name do
10   - run_code = ''
11   - RakeFileUtils.verbose(@verbose) do
12   - run_code =
13   - case @loader
14   - when :direct
15   - "-e 'ARGV.each{|f| load f}'"
16   - when :testrb
17   - "-S testrb #{fix}"
18   - when :rake
19   - rake_loader
  4 +module Rails
  5 + # Don't abort when tests fail; move on the next test task.
  6 + # Silence the default description to cut down on `rake -T` noise.
  7 + class SubTestTask < Rake::TestTask
  8 + # Create the tasks defined by this task lib.
  9 + def define
  10 + lib_path = @libs.join(File::PATH_SEPARATOR)
  11 + task @name do
  12 + run_code = ''
  13 + RakeFileUtils.verbose(@verbose) do
  14 + run_code =
  15 + case @loader
  16 + when :direct
  17 + "-e 'ARGV.each{|f| load f}'"
  18 + when :testrb
  19 + "-S testrb #{fix}"
  20 + when :rake
  21 + rake_loader
  22 + end
  23 + @ruby_opts.unshift( "-I\"#{lib_path}\"" )
  24 + @ruby_opts.unshift( "-w" ) if @warning
  25 +
  26 + begin
  27 + ruby @ruby_opts.join(" ") +
  28 + " \"#{run_code}\" " +
  29 + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
  30 + " #{option_list}"
  31 + rescue => error
  32 + warn "Error running #{@name}: #{error.inspect}"
20 33 end
21   - @ruby_opts.unshift( "-I\"#{lib_path}\"" )
22   - @ruby_opts.unshift( "-w" ) if @warning
23   - ruby @ruby_opts.join(" ") +
24   - " \"#{run_code}\" " +
25   - file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
26   - " #{option_list}"
  34 + end
27 35 end
  36 + self
28 37 end
29   - self
30 38 end
31 39 end
32 40
@@ -76,20 +84,7 @@ task :default => :test
76 84
77 85 desc 'Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)'
78 86 task :test do
79   - tests_to_run = ENV['TEST'] ? ["test:single"] : %w(test:units test:functionals test:integration)
80   - errors = tests_to_run.collect do |task|
81   - begin
82   - Rake::Task[task].invoke
83   - nil
84   - rescue => e
85   - { :task => task, :exception => e }
86   - end
87   - end.compact
88   -
89   - if errors.any?
90   - puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
91   - abort
92   - end
  87 + Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke
93 88 end
94 89
95 90 namespace :test do
@@ -97,6 +92,8 @@ namespace :test do
97 92 # Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
98 93 end
99 94
  95 + task :run => %w(test:units test:functionals test:integration)
  96 +
100 97 Rake::TestTask.new(:recent => "test:prepare") do |t|
101 98 since = TEST_CHANGES_SINCE
102 99 touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
@@ -134,33 +131,33 @@ namespace :test do
134 131 t.libs << "test"
135 132 end
136 133
137   - TestTaskWithoutDescription.new(:units => "test:prepare") do |t|
  134 + Rails::SubTestTask.new(:units => "test:prepare") do |t|
138 135 t.libs << "test"
139 136 t.pattern = 'test/unit/**/*_test.rb'
140 137 end
141 138
142   - TestTaskWithoutDescription.new(:functionals => "test:prepare") do |t|
  139 + Rails::SubTestTask.new(:functionals => "test:prepare") do |t|
143 140 t.libs << "test"
144 141 t.pattern = 'test/functional/**/*_test.rb'
145 142 end
146 143
147   - TestTaskWithoutDescription.new(:integration => "test:prepare") do |t|
  144 + Rails::SubTestTask.new(:integration => "test:prepare") do |t|
148 145 t.libs << "test"
149 146 t.pattern = 'test/integration/**/*_test.rb'
150 147 end
151 148
152   - TestTaskWithoutDescription.new(:benchmark => 'test:prepare') do |t|
  149 + Rails::SubTestTask.new(:benchmark => 'test:prepare') do |t|
153 150 t.libs << 'test'
154 151 t.pattern = 'test/performance/**/*_test.rb'
155 152 t.options = '-- --benchmark'
156 153 end
157 154
158   - TestTaskWithoutDescription.new(:profile => 'test:prepare') do |t|
  155 + Rails::SubTestTask.new(:profile => 'test:prepare') do |t|
159 156 t.libs << 'test'
160 157 t.pattern = 'test/performance/**/*_test.rb'
161 158 end
162 159
163   - TestTaskWithoutDescription.new(:plugins => :environment) do |t|
  160 + Rails::SubTestTask.new(:plugins => :environment) do |t|
164 161 t.libs << "test"
165 162
166 163 if ENV['PLUGIN']

0 comments on commit e854848

Please sign in to comment.
Something went wrong with that request. Please try again.