class Attestify::AssertionResults::FailureDetail

Contains details of a failure, including the message and backtrace information.

Constants

ATTESTIFY_LIB

Attributes

backtrace_locations[R]
message[R]
type[R]

Public Class Methods

for_error(exception) click to toggle source
# File lib/attestify/assertion_results.rb, line 68
def self.for_error(exception)
  new("#{exception.class.name}: #{exception.message}", exception.backtrace_locations, :error)
end
new(message, backtrace_locations, type = :failure) click to toggle source
# File lib/attestify/assertion_results.rb, line 62
def initialize(message, backtrace_locations, type = :failure)
  @message = message
  @backtrace_locations = simplify_backtrace_locations(backtrace_locations)
  @type = type
end

Private Instance Methods

location_in_attestify?(location) click to toggle source
# File lib/attestify/assertion_results.rb, line 85
def location_in_attestify?(location)
  path = File.realpath(location.absolute_path)
  return false if path.size < ATTESTIFY_LIB.size
  return false unless path[0...ATTESTIFY_LIB.size] == ATTESTIFY_LIB
  path[ATTESTIFY_LIB.size] == File::SEPARATOR
end
simplify_backtrace_locations(backtrace_locations) click to toggle source
# File lib/attestify/assertion_results.rb, line 74
def simplify_backtrace_locations(backtrace_locations)
  result = backtrace_locations.dup
  result.pop while !result.empty? && !location_in_attestify?(result.last)
  result.pop while !result.empty? && location_in_attestify?(result.last)
  result
rescue StandardError
  # In case of a disaster, use the original locations, otherwise
  # tests that should fail would seem to succeed.
  backtrace_locations
end