Class: Assert::Result::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/assert/result.rb,
lib/assert/result.rb

Direct Known Subclasses

Error, Fail, Ignore, Pass, Skip

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build_data) ⇒ Base

Returns a new instance of Base.


49
50
51
52
# File 'lib/assert/result.rb', line 49

def initialize(build_data)
  @build_data = build_data
  @with_bt    = nil
end

Class Method Details

.for_test(test, message, bt) ⇒ Object


39
40
41
42
43
44
45
46
47
# 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

.nameObject


35
36
37
# File 'lib/assert/result.rb', line 35

def self.name
  ""
end

.typeObject


31
32
33
# File 'lib/assert/result.rb', line 31

def self.type
  :unknown
end

Instance Method Details

#==(other) ⇒ Object


151
152
153
154
155
156
157
# 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

#backtraceObject


91
92
93
# File 'lib/assert/result.rb', line 91

def backtrace
  @backtrace ||= (@build_data[:backtrace] || Backtrace.new([]))
end

#file_lineObject


125
126
127
# File 'lib/assert/result.rb', line 125

def file_line
  @file_line ||= Assert::FileLine.parse(src_line)
end

#file_nameObject


129
130
131
# File 'lib/assert/result.rb', line 129

def file_name
  file_line.file
end

#inspectObject


159
160
161
162
163
164
# 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_numObject


133
134
135
# File 'lib/assert/result.rb', line 133

def line_num
  file_line.line.to_i
end

#messageObject


83
84
85
# File 'lib/assert/result.rb', line 83

def message
  @message ||= (@build_data[:message] || "")
end

#nameObject


58
59
60
# File 'lib/assert/result.rb', line 58

def name
  @name ||= (@build_data[:name] || self.class.name.to_s)
end

#outputObject


87
88
89
# File 'lib/assert/result.rb', line 87

def output
  @output ||= (@build_data[:output] || "")
end

#set_backtrace(bt) ⇒ Object

we choose to implement this way instead of using an `attr_writer` to be consistant with how you override exception backtraces.


101
102
103
104
105
106
# 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) ⇒ Object

set the given with bt and the src line for with bt


109
110
111
112
113
114
115
# 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_lineObject


121
122
123
# File 'lib/assert/result.rb', line 121

def src_line
  @src_line ||= first_filtered_bt_line(backtrace)
end

#test_file_lineObject


66
67
68
69
# 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_nameObject


71
72
73
# File 'lib/assert/result.rb', line 71

def test_file_name
  test_file_line.file
end

#test_idObject


79
80
81
# File 'lib/assert/result.rb', line 79

def test_id
  test_file_line.to_s
end

#test_line_numObject


75
76
77
# File 'lib/assert/result.rb', line 75

def test_line_num
  test_file_line.line.to_i
end

#test_nameObject


62
63
64
# File 'lib/assert/result.rb', line 62

def test_name
  @test_name ||= (@build_data[:test_name] || "")
end

#to_sObject


145
146
147
148
149
# File 'lib/assert/result.rb', line 145

def to_s
  ["#{name.upcase}: #{test_name}", message, trace]
    .reject(&:empty?)
    .join("\n")
end

#to_symObject


141
142
143
# File 'lib/assert/result.rb', line 141

def to_sym
  type
end

#traceObject


95
96
97
# File 'lib/assert/result.rb', line 95

def trace
  @trace ||= build_trace
end

#typeObject


54
55
56
# File 'lib/assert/result.rb', line 54

def type
  @type ||= (@build_data[:type] || self.class.type).to_sym
end

#with_bt_set?Boolean

Returns:

  • (Boolean)

117
118
119
# File 'lib/assert/result.rb', line 117

def with_bt_set?
  !@with_bt.nil?
end