Class: Spoom::Sorbet::Errors::Error

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/spoom/sorbet/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, line, message, code, more = []) ⇒ Error

: (String? file, Integer? line, String? message, Integer? code, ?Array more) -> void



166
167
168
169
170
171
172
173
# File 'lib/spoom/sorbet/errors.rb', line 166

def initialize(file, line, message, code, more = [])
  @file = file
  @line = line
  @message = message
  @code = code
  @more = more
  @files_from_error_sections = Set.new #: Set[String]
end

Instance Attribute Details

#codeObject (readonly)

: Integer?



156
157
158
# File 'lib/spoom/sorbet/errors.rb', line 156

def code
  @code
end

#fileObject (readonly)

: String?



153
154
155
# File 'lib/spoom/sorbet/errors.rb', line 153

def file
  @file
end

#files_from_error_sectionsObject (readonly)

Other files associated with the error : Set



163
164
165
# File 'lib/spoom/sorbet/errors.rb', line 163

def files_from_error_sections
  @files_from_error_sections
end

#lineObject (readonly)

: Integer?



156
157
158
# File 'lib/spoom/sorbet/errors.rb', line 156

def line
  @line
end

#messageObject (readonly)

: String?



153
154
155
# File 'lib/spoom/sorbet/errors.rb', line 153

def message
  @message
end

#moreObject (readonly)

: Array



159
160
161
# File 'lib/spoom/sorbet/errors.rb', line 159

def more
  @more
end

Instance Method Details

#<=>(other) ⇒ Object

By default errors are sorted by location : (untyped other) -> Integer



177
178
179
180
181
# File 'lib/spoom/sorbet/errors.rb', line 177

def <=>(other)
  return 0 unless other.is_a?(Error)

  [file, line, code, message] <=> [other.file, other.line, other.code, other.message]
end

#to_junit_xml_elementObject

: -> REXML::Element



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/spoom/sorbet/errors.rb', line 189

def to_junit_xml_element
  testcase_element = REXML::Element.new("testcase")
  # Unlike traditional test suites, we can't report all tests
  # regardless of outcome; we only have errors to report. As a
  # result we reinterpret the definitions of the test properties
  # bit: the error message becomes the test name and the full error
  # info gets plugged into the failure body along with file/line
  # information (displayed in Jenkins as the "Stacktrace" for the
  # error).
  testcase_element.add_attributes(
    "name" => message,
    "file" => file,
    "line" => line,
  )
  failure_element = testcase_element.add_element("failure")
  failure_element.add_attributes(
    "type" => code,
  )
  explanation_text = [
    "In file #{file}:\n",
    *more,
  ].join.chomp
  # Use CDATA so that parsers know the whitespace is significant.
  failure_element.add(REXML::CData.new(explanation_text))

  testcase_element
end

#to_sObject

: -> String



184
185
186
# File 'lib/spoom/sorbet/errors.rb', line 184

def to_s
  "#{file}:#{line}: #{message} (#{code})"
end