require "cgi" module Teaspoon module Formatters class JunitFormatter < Base protected def log_runner(result) log_line(%{}) log_line(%{}) log_line(%{}) end def log_suite(result) log_end_suite log_line(%{}) end def log_passing_spec(result) log_junit_spec(suite: result.suite, label: result.label) end def log_pending_spec(result) log_junit_spec(suite: result.suite, label: result.label) do log_line(%{ }) end end def log_failing_spec(result) log_junit_spec(suite: result.suite, label: result.label) do log_line(%{ #{cdata(result.message)}}) end end def log_result(_result) log_end_suite end def log_coverage(message) properties = "#{cdata(message)}" log_line(%{\n#{properties}\n}) end def log_threshold_failure(message) log_line(%{}) log_junit_spec(suite: "Coverage thresholds", label: "were not met") do log_line(%{ #{cdata(message)}}) end log_line(%{}) end def log_complete(_failure_count) log_line(%{\n}) end private def log_end_suite log_line(%{}) if @last_suite end def log_junit_spec(opts, &_block) log_line(%{}) yield if block_given? log_line(%{#{cdata(@stdout)}}) unless @stdout.blank? log_line(%{}) end def escape(str) CGI::escapeHTML(str) end def cdata(str) "\n\n" end end end end