Class: PDK::Report::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/pdk/report/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Event

Initailises a new PDK::Report::Event object.

Options Hash (data):

  • :file (String) — default: see #file
  • :line (Integer) — default: see #line
  • :column (Integer) — default: see #column
  • :source (String) — default: see #source
  • :message (String) — default: see #message
  • :severity (String) — default: see #severity
  • :test (String) — default: see #test
  • :state (Symbol) — default: see #state
  • :trace (Array) — default: see #trace


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

#columnInteger (readonly)



17
18
19
# File 'lib/pdk/report/event.rb', line 17

def column
  @column
end

#fileString (readonly)



9
10
11
# File 'lib/pdk/report/event.rb', line 9

def file
  @file
end

#lineInteger (readonly)



13
14
15
# File 'lib/pdk/report/event.rb', line 13

def line
  @line
end

#messageString (readonly)



25
26
27
# File 'lib/pdk/report/event.rb', line 25

def message
  @message
end

#severityString (readonly)



29
30
31
# File 'lib/pdk/report/event.rb', line 29

def severity
  @severity
end

#sourceString (readonly)



21
22
23
# File 'lib/pdk/report/event.rb', line 21

def source
  @source
end

#stateSymbol (readonly)



36
37
38
# File 'lib/pdk/report/event.rb', line 36

def state
  @state
end

#testString (readonly)



32
33
34
# File 'lib/pdk/report/event.rb', line 32

def test
  @test
end

#traceArray (readonly)



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

#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_junitREXML::Element

Renders the event as a JUnit XML testcase.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pdk/report/event.rb', line 118

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'] = message
    failure.text = to_text
    testcase.elements << failure
  elsif skipped?
    testcase.add_element('skipped')
  end

  testcase
end

#to_textString

Renders the event in a clang style text format.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/pdk/report/event.rb', line 94

def to_text
  location = [file, line, column].compact.join(':')
  location = nil if location.empty?

  # TODO: maybe add trace
  header = [severity, source, location, message].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