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
Constant Summary
collapse
- AST_SCENARIO_OUTLINE =
TODO: remove coupling to types
Core::Ast::ScenarioOutline
- AST_EXAMPLE_ROW =
LegacyApi::Ast::ExampleTableRow
Instance Method Summary
collapse
-
#after_background(*args) ⇒ Object
-
#after_examples(*args) ⇒ Object
-
#after_feature(feature) ⇒ Object
-
#after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) ⇒ Object
-
#after_steps(steps) ⇒ Object
-
#after_table_row(table_row) ⇒ Object
-
#after_test_case(test_case, result) ⇒ Object
-
#before_background(*args) ⇒ Object
-
#before_examples(*args) ⇒ Object
-
#before_feature(feature) ⇒ Object
-
#before_feature_element(feature_element) ⇒ Object
-
#before_steps(steps) ⇒ Object
-
#before_table_row(table_row) ⇒ Object
-
#before_test_case(test_case) ⇒ Object
-
#feature_name(keyword, name) ⇒ Object
-
#initialize(runtime, io, options) ⇒ Junit
constructor
-
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
Methods included from Io
#ensure_dir, #ensure_file, #ensure_io
Constructor Details
#initialize(runtime, io, options) ⇒ Junit
Returns a new instance of Junit.
23
24
25
26
|
# File 'lib/cucumber/formatter/junit.rb', line 23
def initialize(runtime, io, options)
@reportdir = ensure_dir(io, "junit")
@options = options
end
|
Instance Method Details
#after_background(*args) ⇒ Object
73
74
75
|
# File 'lib/cucumber/formatter/junit.rb', line 73
def after_background(*args)
@in_background = false
end
|
#after_examples(*args) ⇒ Object
107
108
109
|
# File 'lib/cucumber/formatter/junit.rb', line 107
def after_examples(*args)
@in_examples = false
end
|
#after_feature(feature) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/cucumber/formatter/junit.rb', line 44
def after_feature(feature)
@testsuite = Builder::XmlMarkup.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_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/cucumber/formatter/junit.rb', line 138
def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
if @options[:expand] and @in_examples
if not @exception and exception
@exception = exception
end
end
end
|
#after_steps(steps) ⇒ Object
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/cucumber/formatter/junit.rb', line 91
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/cucumber/formatter/junit.rb', line 117
def after_table_row(table_row)
return unless @in_examples and AST_EXAMPLE_ROW === 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
|
#after_test_case(test_case, result) ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/cucumber/formatter/junit.rb', line 146
def after_test_case(test_case, result)
if @options[:expand] and test_case.keyword == "Scenario Outline"
test_case_name = NameBuilder.new(test_case)
@scenario = test_case_name.outline_name
@output = "#{test_case.keyword}: #{@scenario}\n\n"
if result.failed?
@output += "Example row: #{test_case_name.row_name}\n"
@output += "\nMessage:\n"
end
test_case_result = ResultBuilder.new(result)
build_testcase(test_case_result.test_case_duration, test_case_result.status, @exception, test_case_name.name_suffix)
end
end
|
#before_background(*args) ⇒ Object
69
70
71
|
# File 'lib/cucumber/formatter/junit.rb', line 69
def before_background(*args)
@in_background = true
end
|
#before_examples(*args) ⇒ Object
102
103
104
105
|
# File 'lib/cucumber/formatter/junit.rb', line 102
def before_examples(*args)
@header_row = true
@in_examples = true
end
|
#before_feature(feature) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/cucumber/formatter/junit.rb', line 28
def before_feature(feature)
@current_feature = feature
@failures = @errors = @tests = @skipped = 0
@builder = Builder::XmlMarkup.new( :indent => 2 )
@time = 0
@interceptedout = Interceptor::Pipe.wrap(:stdout)
@interceptederr = Interceptor::Pipe.wrap(:stderr)
end
|
#before_feature_element(feature_element) ⇒ Object
39
40
41
42
|
# File 'lib/cucumber/formatter/junit.rb', line 39
def before_feature_element(feature_element)
@in_examples = AST_SCENARIO_OUTLINE === feature_element
@steps_start = Time.now
end
|
#before_steps(steps) ⇒ Object
88
89
|
# File 'lib/cucumber/formatter/junit.rb', line 88
def before_steps(steps)
end
|
#before_table_row(table_row) ⇒ Object
111
112
113
114
115
|
# File 'lib/cucumber/formatter/junit.rb', line 111
def before_table_row(table_row)
return unless @in_examples
@table_start = Time.now
end
|
#before_test_case(test_case) ⇒ Object
132
133
134
135
136
|
# File 'lib/cucumber/formatter/junit.rb', line 132
def before_test_case(test_case)
if @options[:expand] and test_case.keyword == "Scenario Outline"
@exception = nil
end
end
|
#feature_name(keyword, name) ⇒ Object
77
78
79
80
81
|
# File 'lib/cucumber/formatter/junit.rb', line 77
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
83
84
85
86
|
# File 'lib/cucumber/formatter/junit.rb', line 83
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
|