class Assert::Result::Base
Public Class Methods
for_test(test, message, bt)
click to toggle source
# File lib/assert/result.rb, line 39 def self.for_test(test, message, bt) new({ test_name: test.name, test_file_line: test.file_line, message: message, output: test.output, backtrace: Backtrace.new(bt), }) end
name()
click to toggle source
# File lib/assert/result.rb, line 35 def self.name "" end
new(build_data)
click to toggle source
# File lib/assert/result.rb, line 49 def initialize(build_data) @build_data = build_data @with_bt = nil end
type()
click to toggle source
# File lib/assert/result.rb, line 31 def self.type :unknown end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/assert/result.rb, line 151 def ==(other) if other.is_a?(self.class) type == other.type && message == other.message else super end end
backtrace()
click to toggle source
# File lib/assert/result.rb, line 91 def backtrace @backtrace ||= (@build_data[:backtrace] || Backtrace.new([])) end
file_line()
click to toggle source
# File lib/assert/result.rb, line 125 def file_line @file_line ||= Assert::FileLine.parse(src_line) end
file_name()
click to toggle source
# File lib/assert/result.rb, line 129 def file_name file_line.file end
inspect()
click to toggle source
# File lib/assert/result.rb, line 159 def inspect "#<#{self.class}:#{"0x0%x" % (object_id << 1)} "\ "@message=#{message.inspect} "\ "@file_line=#{file_line.to_s.inspect} "\ "@test_file_line=#{test_file_line.to_s.inspect}>" end
line_num()
click to toggle source
# File lib/assert/result.rb, line 133 def line_num file_line.line.to_i end
message()
click to toggle source
# File lib/assert/result.rb, line 83 def message @message ||= (@build_data[:message] || "") end
name()
click to toggle source
# File lib/assert/result.rb, line 58 def name @name ||= (@build_data[:name] || self.class.name.to_s) end
output()
click to toggle source
# File lib/assert/result.rb, line 87 def output @output ||= (@build_data[:output] || "") end
set_backtrace(bt)
click to toggle source
we choose to implement this way instead of using an ‘attr_writer` to be consistant with how you override exception backtraces.
# File lib/assert/result.rb, line 101 def set_backtrace(bt) @backtrace = Backtrace.new(bt) @src_line = nil @file_line = nil @trace = nil end
set_with_bt(with_bt)
click to toggle source
set the given with bt and the src line for with bt
# File lib/assert/result.rb, line 109 def set_with_bt(with_bt) return if with_bt.nil? @with_bt = with_bt @src_line = with_bt.first @file_line = nil @trace = nil end
src_line()
click to toggle source
# File lib/assert/result.rb, line 121 def src_line @src_line ||= first_filtered_bt_line(backtrace) end
test_file_line()
click to toggle source
# File lib/assert/result.rb, line 66 def test_file_line @test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse("")) end
test_file_name()
click to toggle source
# File lib/assert/result.rb, line 71 def test_file_name test_file_line.file end
test_id()
click to toggle source
# File lib/assert/result.rb, line 79 def test_id test_file_line.to_s end
test_line_num()
click to toggle source
# File lib/assert/result.rb, line 75 def test_line_num test_file_line.line.to_i end
test_name()
click to toggle source
# File lib/assert/result.rb, line 62 def test_name @test_name ||= (@build_data[:test_name] || "") end
to_s()
click to toggle source
# File lib/assert/result.rb, line 145 def to_s ["#{name.upcase}: #{test_name}", message, trace] .reject(&:empty?) .join("\n") end
to_sym()
click to toggle source
# File lib/assert/result.rb, line 141 def to_sym type end
trace()
click to toggle source
# File lib/assert/result.rb, line 95 def trace @trace ||= build_trace end
type()
click to toggle source
# File lib/assert/result.rb, line 54 def type @type ||= (@build_data[:type] || self.class.type).to_sym end
with_bt_set?()
click to toggle source
# File lib/assert/result.rb, line 117 def with_bt_set? !@with_bt.nil? end
Private Instance Methods
build_trace()
click to toggle source
By default, a result’s trace is its ‘src_line`. If a with bt has been set, display it in full along with the “original src line” (the first filtered line of the backtrace). This is overridden for error results as they always show their full backtrace.
# File lib/assert/result.rb, line 172 def build_trace if with_bt_set? Backtrace.to_s(@with_bt + [first_filtered_bt_line(backtrace)]) else src_line end end
first_filtered_bt_line(backtrace)
click to toggle source
if the filtered backtrace is empty, just use the backtrace itself (this should only occur if the result is an error from a line in Assert’s non-test code).
# File lib/assert/result.rb, line 183 def first_filtered_bt_line(backtrace) ((fbt = backtrace.filtered).empty? ? backtrace : fbt).first.to_s end