Class: PDK::Report::Event
- Inherits:
-
Object
- Object
- PDK::Report::Event
- Defined in:
- lib/pdk/report/event.rb
Instance Attribute Summary collapse
-
#column ⇒ Integer
readonly
The column number in the line of the file that the event is in reference to.
-
#file ⇒ String
readonly
The path to the file that the event is in reference to.
-
#line ⇒ Integer
readonly
The line number in the file that the event is in reference to.
-
#message ⇒ String
readonly
A freeform String containing a human readable message describing the event.
-
#severity ⇒ String
readonly
The severity of the event as reported by the underlying tool.
-
#source ⇒ String
readonly
The name of the source of the event (usually the name of the validation or testing tool that generated the event).
-
#state ⇒ Symbol
readonly
The state of the event.
-
#test ⇒ String
readonly
The name of the test that generated the event.
-
#trace ⇒ Array
readonly
Array of full stack trace lines associated with event.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Checks if the event is the result of a test that could not complete due to an error.
-
#failure? ⇒ Boolean
Checks if the event is the result of a failing test.
-
#initialize(data) ⇒ Event
constructor
Initailises a new PDK::Report::Event object.
-
#pass? ⇒ Boolean
Checks if the event is the result of a passing test.
-
#rspec_puppet_coverage? ⇒ Boolean
Checks if the event stores the result of an rspec-puppet coverage check.
-
#skipped? ⇒ Boolean
Checks if the event is the result of test that was not run.
-
#to_junit ⇒ REXML::Element
Renders the event as a JUnit XML testcase.
-
#to_text ⇒ String
Renders the event in a clang style text format.
Constructor Details
#initialize(data) ⇒ Event
Initailises a new PDK::Report::Event object.
55 56 57 58 59 |
# File 'lib/pdk/report/event.rb', line 55 def initialize(data) sanitise_data(data).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#column ⇒ Integer (readonly)
Returns The column number in the line of the file that the event is in reference to.
17 18 19 |
# File 'lib/pdk/report/event.rb', line 17 def column @column end |
#file ⇒ String (readonly)
Returns The path to the file that the event is in reference to.
9 10 11 |
# File 'lib/pdk/report/event.rb', line 9 def file @file end |
#line ⇒ Integer (readonly)
Returns The line number in the file that the event is in reference to.
13 14 15 |
# File 'lib/pdk/report/event.rb', line 13 def line @line end |
#message ⇒ String (readonly)
Returns A freeform String containing a human readable message describing the event.
25 26 27 |
# File 'lib/pdk/report/event.rb', line 25 def @message end |
#severity ⇒ String (readonly)
Returns The severity of the event as reported by the underlying tool.
29 30 31 |
# File 'lib/pdk/report/event.rb', line 29 def severity @severity end |
#source ⇒ String (readonly)
Returns The name of the source of the event (usually the name of the validation or testing tool that generated the event).
21 22 23 |
# File 'lib/pdk/report/event.rb', line 21 def source @source end |
#state ⇒ Symbol (readonly)
Returns The state of the event. :passed, :failure, :error, or :skipped.
36 37 38 |
# File 'lib/pdk/report/event.rb', line 36 def state @state end |
#test ⇒ String (readonly)
Returns The name of the test that generated the event.
32 33 34 |
# File 'lib/pdk/report/event.rb', line 32 def test @test end |
#trace ⇒ Array (readonly)
Returns Array of full stack trace lines associated with event.
39 40 41 |
# File 'lib/pdk/report/event.rb', line 39 def trace @trace end |
Instance Method Details
#error? ⇒ Boolean
Checks if the event is the result of a test that could not complete due to an error.
72 73 74 |
# File 'lib/pdk/report/event.rb', line 72 def error? state == :error end |
#failure? ⇒ Boolean
Checks if the event is the result of a failing test.
79 80 81 |
# File 'lib/pdk/report/event.rb', line 79 def failure? state == :failure end |
#pass? ⇒ Boolean
Checks if the event is the result of a passing test.
64 65 66 |
# File 'lib/pdk/report/event.rb', line 64 def pass? state == :passed end |
#rspec_puppet_coverage? ⇒ Boolean
Checks if the event stores the result of an rspec-puppet coverage check.
Due to the implementation details of this check, the ‘file` value for this event will always point to the coverage.rb file in rspec-puppet, making it easy to filter out.
100 101 102 103 |
# File 'lib/pdk/report/event.rb', line 100 def rspec_puppet_coverage? @rspec_puppet_coverage_pattern ||= File.join('**', 'lib', 'rspec-puppet', 'coverage.rb') source == 'rspec' && File.fnmatch?(@rspec_puppet_coverage_pattern, File.(file)) end |
#skipped? ⇒ Boolean
Checks if the event is the result of test that was not run. This includes pending tests (that are run but have an expected failure result).
87 88 89 |
# File 'lib/pdk/report/event.rb', line 87 def skipped? state == :skipped end |
#to_junit ⇒ REXML::Element
Renders the event as a JUnit XML testcase.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/pdk/report/event.rb', line 134 def to_junit testcase = REXML::Element.new('testcase') testcase.attributes['classname'] = [source, test].compact.join('.') testcase.attributes['name'] = [file, line, column].compact.join(':') testcase.attributes['time'] = 0 if failure? failure = REXML::Element.new('failure') failure.attributes['type'] = severity failure.attributes['message'] = failure.text = to_text testcase.elements << failure elsif skipped? testcase.add_element('skipped') end testcase end |
#to_text ⇒ String
Renders the event in a clang style text format.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pdk/report/event.rb', line 108 def to_text return if rspec_puppet_coverage? location = [file, line, column].compact.join(':') location = nil if location.empty? # TODO: maybe add trace header = [severity, source, location, ].compact.join(': ') if source == 'rspec' result = [header, " #{test}"] context = context_lines unless context.nil? result << ' Failure/Error:' result.concat(context) result << "\n" end result.compact.join("\n") else header end end |