Module: BareTest::Run::XML

Extended by:
Formatter
Defined in:
lib/baretest/run/xml.rb

Overview

XML runner is invoked with ‘-f xml` or `–format xml`. This runner provides xml output as a simple machine readable format. The schema is relatively simple:

<tests>
  <suite description="the suites description">
    <test>
      <file>the file the test was defined in</file>
      <line>the line the assertion starts on</line>
      <status>one of: success, pending, skipped, failure, error</status>
      <description>the description of the test</test>
    </test>
    ...many tests and/or suites
  </suite>
</tests>
<report>
  <duration>the duration in seconds as a float</duration>
  <count type="the counters name, see BareTest::Run#count">integer</count>
  ...many counts
</report>
<status>The final status, one of: success, incomplete, failure, error</status>

Instance Attribute Summary

Attributes included from Formatter

#command

Instance Method Summary collapse

Methods included from Formatter

env_option, extended, initialize_options, option, option_defaults, text

Instance Method Details

#run_allObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/baretest/run/xml.rb', line 41

def run_all
  @depth  = 1
  @indent = @options[:indent]

  puts '<?xml version="1.0" encoding="utf-8"?>',
       '<tests>'
  start  = Time.now
  super
  stop   = Time.now
  puts %{</tests>},
       %{<report>},
       %{#{@indent}<duration>#{stop-start}</duration>}
  @count.each { |key, value|
    puts %{#{@indent}<count type="#{key}">#{value}</count>}
  }
  puts %{</report>},
       %{<status>#{global_status}</status>}
end

#run_suite(suite) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/baretest/run/xml.rb', line 60

def run_suite(suite)
  puts %{#{@indent*@depth}<suite description="#{suite.description}">}
  @depth += 1
  super
  @depth -= 1
  puts %{#{@indent*@depth}</suite>}
end

#run_test(assertion, setup) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/baretest/run/xml.rb', line 68

def run_test(assertion, setup)
  rv = super
  puts %{#{@indent*@depth}<test>},
       %{#{@indent*@depth}#{@indent}<file>#{assertion.file}</file>},
       %{#{@indent*@depth}#{@indent}<line>#{assertion.line}</line>},
       %{#{@indent*@depth}#{@indent}<status>#{rv.status}</status>},
       %{#{@indent*@depth}#{@indent}<description>#{assertion.description}</description>},
       %{#{@indent*@depth}</test>}
  rv
end