Class: AISpec::Core::Reporters::JUnit

Inherits:
Base
  • Object
show all
Defined in:
lib/aispec/core/reporters/junit.rb

Instance Attribute Summary

Attributes inherited from Base

#output_io, #results

Instance Method Summary collapse

Methods inherited from Base

get, #initialize, register

Constructor Details

This class inherits a constructor from AISpec::Core::Reporters::Base

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/aispec/core/reporters/junit.rb', line 12

def render
  contract = results[:contract]
  stats = results[:statistics]
  summary = stats.summary

  doc = REXML::Document.new
  doc << REXML::XMLDecl.new("1.0", "UTF-8")

  testsuite = doc.add_element("testsuite", {
    "name" => contract.name,
    "tests" => summary[:total_assertions].to_s,
    "failures" => summary[:failed_assertions].to_s,
    "time" => (summary[:mean_latency] / 1000.0).to_s
  })

  results[:runs].each_with_index do |run, i|
    run[:assertion_results].each do |ar|
      tc = testsuite.add_element("testcase", {
        "classname" => "#{contract.name}.Case#{i + 1}",
        "name" => ar.name.to_s,
        "time" => (run[:latency_ms] / 1000.0).to_s
      })

      unless ar.passed?
        failure = tc.add_element("failure", { "message" => ar.message })
        failure.text = ar.message
      end
    end
  end

  output = ""
  doc.write(output, 2)
  output_io.puts output
  output
end