2015-06-13 05:56:32 -04:00
|
|
|
require "active_support/core_ext/class/attribute"
|
2015-01-23 16:05:31 -05:00
|
|
|
require "minitest"
|
|
|
|
|
|
|
|
module Rails
|
|
|
|
class TestUnitReporter < Minitest::StatisticsReporter
|
2015-06-13 05:56:32 -04:00
|
|
|
class_attribute :executable
|
|
|
|
self.executable = "bin/rails test"
|
|
|
|
|
2015-08-30 06:33:37 -04:00
|
|
|
def record(result)
|
|
|
|
super
|
|
|
|
|
|
|
|
if output_inline? && result.failure && (!result.skipped? || options[:verbose])
|
|
|
|
io.puts
|
|
|
|
io.puts
|
|
|
|
io.puts result.failures.map(&:message)
|
|
|
|
io.puts
|
|
|
|
io.puts format_rerun_snippet(result)
|
|
|
|
io.puts
|
|
|
|
end
|
2015-09-28 14:27:30 -04:00
|
|
|
|
|
|
|
if fail_fast? && result.failure && !result.error? && !result.skipped?
|
|
|
|
raise Interrupt
|
|
|
|
end
|
2015-08-30 06:33:37 -04:00
|
|
|
end
|
|
|
|
|
2015-01-23 16:05:31 -05:00
|
|
|
def report
|
2015-08-30 06:33:37 -04:00
|
|
|
return if output_inline? || filtered_results.empty?
|
2015-01-23 16:05:31 -05:00
|
|
|
io.puts
|
2015-01-24 05:48:17 -05:00
|
|
|
io.puts "Failed tests:"
|
2015-01-23 16:05:31 -05:00
|
|
|
io.puts
|
|
|
|
io.puts aggregated_results
|
|
|
|
end
|
|
|
|
|
|
|
|
def aggregated_results # :nodoc:
|
2015-08-30 06:33:37 -04:00
|
|
|
filtered_results.map { |result| format_rerun_snippet(result) }.join "\n"
|
2015-01-23 16:05:31 -05:00
|
|
|
end
|
2015-03-21 08:15:56 -04:00
|
|
|
|
2015-06-22 18:53:17 -04:00
|
|
|
def filtered_results
|
|
|
|
if options[:verbose]
|
|
|
|
results
|
|
|
|
else
|
|
|
|
results.reject(&:skipped?)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 08:15:56 -04:00
|
|
|
def relative_path_for(file)
|
|
|
|
file.sub(/^#{Rails.root}\/?/, '')
|
|
|
|
end
|
2015-08-30 06:33:37 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
def output_inline?
|
|
|
|
options.fetch(:output_inline, true)
|
|
|
|
end
|
|
|
|
|
2015-09-28 14:27:30 -04:00
|
|
|
def fail_fast?
|
|
|
|
options[:fail_fast]
|
|
|
|
end
|
|
|
|
|
2015-08-30 06:33:37 -04:00
|
|
|
def format_rerun_snippet(result)
|
|
|
|
location, line = result.method(result.name).source_location
|
|
|
|
"#{self.executable} #{relative_path_for(location)}:#{line}"
|
|
|
|
end
|
2015-01-23 16:05:31 -05:00
|
|
|
end
|
|
|
|
end
|