Class: Cucumber::Formatter::Junit
- Inherits:
-
Object
- Object
- Cucumber::Formatter::Junit
show all
- Includes:
- Io
- Defined in:
- lib/cucumber/formatter/junit.rb
Overview
The formatter used for --format junit
Defined Under Namespace
Classes: UnNamedFeatureError
Instance Method Summary
collapse
Methods included from Io
#ensure_dir, #ensure_file, #ensure_io
Constructor Details
#initialize(runtime, io, options) ⇒ Junit
Returns a new instance of Junit.
18
19
20
21
|
# File 'lib/cucumber/formatter/junit.rb', line 18
def initialize(runtime, io, options)
@reportdir = ensure_dir(io, "junit")
@options = options
end
|
Instance Method Details
#after_background(*args) ⇒ Object
68
69
70
|
# File 'lib/cucumber/formatter/junit.rb', line 68
def after_background(*args)
@in_background = false
end
|
#after_examples(*args) ⇒ Object
102
103
104
|
# File 'lib/cucumber/formatter/junit.rb', line 102
def after_examples(*args)
@in_examples = false
end
|
#after_feature(feature) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/cucumber/formatter/junit.rb', line 39
def after_feature(feature)
@testsuite = OrderedXmlMarkup.new( :indent => 2 )
@testsuite.instruct!
@testsuite.testsuite(
:failures => @failures,
:errors => @errors,
:skipped => @skipped,
:tests => @tests,
:time => "%.6f" % @time,
:name => @feature_name ) do
@testsuite << @builder.target!
@testsuite.tag!('system-out') do
@testsuite.cdata! strip_control_chars(@interceptedout.buffer.join)
end
@testsuite.tag!('system-err') do
@testsuite.cdata! strip_control_chars(@interceptederr.buffer.join)
end
end
write_file(feature_result_filename(feature.file), @testsuite.target!)
Interceptor::Pipe.unwrap! :stdout
Interceptor::Pipe.unwrap! :stderr
end
|
#after_steps(steps) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cucumber/formatter/junit.rb', line 86
def after_steps(steps)
return if @in_background || @in_examples
duration = Time.now - @steps_start
if steps.failed?
steps.each { |step| @output += "#{step.keyword}#{step.name}\n" }
@output += "\nMessage:\n"
end
build_testcase(duration, steps.status, steps.exception)
end
|
#after_table_row(table_row) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/cucumber/formatter/junit.rb', line 112
def after_table_row(table_row)
return unless @in_examples and Cucumber::Ast::OutlineTable::ExampleRow === table_row
duration = Time.now - @table_start
unless @header_row
name_suffix = " (outline example : #{table_row.name})"
if table_row.failed?
@output += "Example row: #{table_row.name}\n"
@output += "\nMessage:\n"
end
build_testcase(duration, table_row.status, table_row.exception, name_suffix)
end
@header_row = false if @header_row
end
|
#before_background(*args) ⇒ Object
64
65
66
|
# File 'lib/cucumber/formatter/junit.rb', line 64
def before_background(*args)
@in_background = true
end
|
#before_examples(*args) ⇒ Object
97
98
99
100
|
# File 'lib/cucumber/formatter/junit.rb', line 97
def before_examples(*args)
@header_row = true
@in_examples = true
end
|
#before_feature(feature) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/cucumber/formatter/junit.rb', line 23
def before_feature(feature)
@current_feature = feature
@failures = @errors = @tests = @skipped = 0
@builder = OrderedXmlMarkup.new( :indent => 2 )
@time = 0
@interceptedout = Interceptor::Pipe.wrap(:stdout)
@interceptederr = Interceptor::Pipe.wrap(:stderr)
end
|
#before_feature_element(feature_element) ⇒ Object
34
35
36
37
|
# File 'lib/cucumber/formatter/junit.rb', line 34
def before_feature_element(feature_element)
@in_examples = Ast::ScenarioOutline === feature_element
@steps_start = Time.now
end
|
#before_steps(steps) ⇒ Object
83
84
|
# File 'lib/cucumber/formatter/junit.rb', line 83
def before_steps(steps)
end
|
#before_table_row(table_row) ⇒ Object
106
107
108
109
110
|
# File 'lib/cucumber/formatter/junit.rb', line 106
def before_table_row(table_row)
return unless @in_examples
@table_start = Time.now
end
|
#feature_name(keyword, name) ⇒ Object
72
73
74
75
76
|
# File 'lib/cucumber/formatter/junit.rb', line 72
def feature_name(keyword, name)
raise UnNamedFeatureError.new(@current_feature.file) if name.empty?
lines = name.split(/\r?\n/)
@feature_name = lines[0]
end
|
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
78
79
80
81
|
# File 'lib/cucumber/formatter/junit.rb', line 78
def scenario_name(keyword, name, file_colon_line, source_indent)
@scenario = (name.nil? || name == "") ? "Unnamed scenario" : name.split("\n")[0]
@output = "#{keyword}: #{@scenario}\n\n"
end
|