Class: JUnitFormatter
Instance Attribute Summary
#exceptions, #tally, #timer
Instance Method Summary
collapse
#switch
#abort, #before, #exception?, #failure?, #print
Constructor Details
Returns a new instance of JUnitFormatter.
6
7
8
9
10
|
# File 'lib/extensions/mspec/mspec/runner/formatters/junit.rb', line 6
def initialize(out=nil)
super
@tests = []
@spec_path = ''
end
|
Instance Method Details
#after(state = nil) ⇒ Object
25
26
27
28
|
# File 'lib/extensions/mspec/mspec/runner/formatters/junit.rb', line 25
def after(state = nil)
super
@tests << {:test => state, :spec => @spec_path, :exception => false} unless exception?
end
|
#exception(exception) ⇒ Object
30
31
32
33
|
# File 'lib/extensions/mspec/mspec/runner/formatters/junit.rb', line 30
def exception(exception)
super
@tests << {:test => exception, :spec => @spec_path, :exception => true}
end
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/extensions/mspec/mspec/runner/formatters/junit.rb', line 35
def finish
switch
time = @timer.elapsed
formatted_time = "%.1f" % time
tests = @tally.counter.examples
errors = @tally.counter.errors
failures = @tally.counter.failures
print <<-XML
<?xml version="1.0" encoding="UTF-8" ?>
<testsuites
testCount="#{tests}"
errorCount="#{errors}"
failureCount="#{failures}"
timeCount="#{formatted_time}" time="#{formatted_time}">
<testsuite
tests="#{tests}"
errors="#{errors}"
failures="#{failures}"
time="#{formatted_time}"
name="Spec Output For #{::RUBY_NAME} (#{::RUBY_VERSION})">
XML
@tests.each do |h|
description = encode_for_xml h[:test].description
spec_class = h[:spec]
if description =~ /^([^\s\.\|:]+)(#|\.|::)([^\s]+)/i
spec_class = $1
end
print <<-XML
<testcase classname="#{spec_class}" name="#{description}" time="0.0">
XML
if h[:exception]
outcome = h[:test].failure? ? "failure" : "error"
message = encode_for_xml h[:test].message
backtrace = encode_for_xml h[:test].backtrace
print <<-XML
<#{outcome} message="error in #{description}" type="#{outcome}">
#{message}
#{backtrace}
</#{outcome}>
XML
end
print <<-XML
</testcase>
XML
end
print <<-XML
</testsuite>
</testsuites>
XML
end
|
#load(state = nil) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/extensions/mspec/mspec/runner/formatters/junit.rb', line 17
def load(state = nil)
spec_path, spec_file = File.split((MSpec.retrieve(:file)+'.rb').gsub(/^spec\//,''))
if (spec_path.empty? || spec_path.nil?) && spec_file =~ /(.*)_spec/i
spec_path = $1
end
@spec_path = encode_for_xml( spec_path.gsub('/','.') )
end
|
12
13
14
15
|
# File 'lib/extensions/mspec/mspec/runner/formatters/junit.rb', line 12
def register
super
MSpec.register :load, self
end
|