Cleanup top-level formatting code

This commit is contained in:
Michael Miller 2019-03-23 16:28:36 -06:00
parent 3fbe6a2760
commit ff20fbe232

View file

@ -7,7 +7,7 @@ module Spectator::Formatting
private JUNIT_XML_FILE = "output.xml" private JUNIT_XML_FILE = "output.xml"
# Name of the top-level test suites block. # Name of the top-level test suites block.
private NAME = "AllTests" private NAME = "Spec"
# Creates the formatter. # Creates the formatter.
# By default, output is sent to STDOUT. # By default, output is sent to STDOUT.
@ -25,16 +25,7 @@ module Spectator::Formatting
# Called when a test suite finishes. # Called when a test suite finishes.
# The results from the entire suite are provided. # The results from the entire suite are provided.
def end_suite(report : Report) def end_suite(report : Report)
@xml.element("testsuites", test_suites_block(report)
tests: report.example_count,
failures: report.failed_count,
errors: report.error_count,
time: report.runtime.total_seconds,
name: NAME) do
report.group_by(&.example.source.path).each do |path, results|
JUnitTestSuite.new(path, results).to_xml(@xml)
end
end
@xml.end_document @xml.end_document
@xml.flush @xml.flush
@io.close @io.close
@ -48,5 +39,24 @@ module Spectator::Formatting
# The result of the test is provided. # The result of the test is provided.
def end_example(result : Result) def end_example(result : Result)
end end
# Creates the "testsuites" block in the XML.
private def test_suites_block(report)
@xml.element("testsuites",
tests: report.example_count,
failures: report.failed_count,
errors: report.error_count,
time: report.runtime.total_seconds,
name: NAME) do
add_test_suites(report)
end
end
# Adds all of the individual test suite blocks.
private def add_test_suites(report)
report.group_by(&.example.source.path).each do |path, results|
JUnitTestSuite.new(path, results).to_xml(@xml)
end
end
end end
end end