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(step_mother, io, options) ⇒ Junit
Returns a new instance of Junit.
17
18
19
20
|
# File 'lib/cucumber/formatter/junit.rb', line 17
def initialize(step_mother, io, options)
@reportdir = ensure_dir(io, "junit")
@options = options
end
|
Instance Method Details
#after_background(*args) ⇒ Object
48
49
50
|
# File 'lib/cucumber/formatter/junit.rb', line 48
def after_background(*args)
@in_background = false
end
|
#after_examples(*args) ⇒ Object
87
88
89
|
# File 'lib/cucumber/formatter/junit.rb', line 87
def after_examples(*args)
@in_examples = false
end
|
#after_feature(feature) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/cucumber/formatter/junit.rb', line 29
def after_feature(feature)
@testsuite = OrderedXmlMarkup.new( :indent => 2 )
@testsuite.instruct!
@testsuite.testsuite(
:failures => @failures,
:errors => @errors,
:tests => @tests,
:time => "%.6f" % @time,
:name => @feature_name ) do
@testsuite << @builder.target!
end
write_file(feature_result_filename(feature.file), @testsuite.target!)
end
|
#after_steps(steps) ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/cucumber/formatter/junit.rb', line 71
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/cucumber/formatter/junit.rb', line 97
def after_table_row(table_row)
return unless @in_examples
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
44
45
46
|
# File 'lib/cucumber/formatter/junit.rb', line 44
def before_background(*args)
@in_background = true
end
|
#before_examples(*args) ⇒ Object
82
83
84
85
|
# File 'lib/cucumber/formatter/junit.rb', line 82
def before_examples(*args)
@header_row = true
@in_examples = true
end
|
#before_feature(feature) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/cucumber/formatter/junit.rb', line 22
def before_feature(feature)
@current_feature = feature
@failures = @errors = @tests = 0
@builder = OrderedXmlMarkup.new( :indent => 2 )
@time = 0
end
|
#before_steps(steps) ⇒ Object
67
68
69
|
# File 'lib/cucumber/formatter/junit.rb', line 67
def before_steps(steps)
@steps_start = Time.now
end
|
#before_table_row(table_row) ⇒ Object
91
92
93
94
95
|
# File 'lib/cucumber/formatter/junit.rb', line 91
def before_table_row(table_row)
return unless @in_examples
@table_start = Time.now
end
|
#feature_name(name) ⇒ Object
52
53
54
55
56
|
# File 'lib/cucumber/formatter/junit.rb', line 52
def feature_name(name)
raise UnNamedFeatureError.new(@current_feature.file) if name.empty?
lines = name.split(/\r?\n/)
@feature_name = lines[0].sub(/Feature\:/, '').strip
end
|
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/cucumber/formatter/junit.rb', line 58
def scenario_name(keyword, name, file_colon_line, source_indent)
scenario_name = name.strip.delete(".\r\n")
scenario_name = "Unnamed scenario" if name.blank?
@scenario = scenario_name
description = "Scenario"
description << " outline" if keyword.include?('Scenario Outline')
@output = "#{description}: #{@scenario}\n\n"
end
|