Skip to content

Instantly share code, notes, and snippets.

@jsl
Created February 8, 2012 22:38
Show Gist options
  • Save jsl/1775007 to your computer and use it in GitHub Desktop.
Save jsl/1775007 to your computer and use it in GitHub Desktop.
Hacked SubTestTask that allows exit status to be returned after failing tests
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
puts "running sub test task #{@name}"
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_command(run_code)) { |ok, res| at_exit { exit res.exitstatus } unless ok }
rescue => error
warn "Error running #{name}: #{error.inspect}"
end
end
end
self
end
private
def ruby_command run_code
@ruby_opts.join(" ") +
" \"#{run_code}\" " +
file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
" #{option_list}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment