Class: Minitest::Heat::Backtrace

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/heat/backtrace.rb,
lib/minitest/heat/backtrace/line_count.rb,
lib/minitest/heat/backtrace/line_parser.rb

Overview

Wrapper for separating backtrace into component parts

Defined Under Namespace

Modules: LineParser Classes: LineCount

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_backtrace) ⇒ self

Creates a more flexible backtrace data structure by parsing the lines of the backtrace to

extract specific subsets of lines for investigating the offending files and line numbers

Parameters:

  • raw_backtrace (Array)

    the array of lines from the backtrace



17
18
19
# File 'lib/minitest/heat/backtrace.rb', line 17

def initialize(raw_backtrace)
  @raw_backtrace = Array(raw_backtrace)
end

Instance Attribute Details

#raw_backtraceObject (readonly)

Returns the value of attribute raw_backtrace.



10
11
12
# File 'lib/minitest/heat/backtrace.rb', line 10

def raw_backtrace
  @raw_backtrace
end

Instance Method Details

#empty?Boolean

Determines if the raw backtrace has values in it

Returns:

  • (Boolean)

    true if there’s no backtrace or it’s empty



24
25
26
# File 'lib/minitest/heat/backtrace.rb', line 24

def empty?
  raw_backtrace.empty?
end

#locationsArray<Location>

All lines of the backtrace converted to Backtrace::LineParser’s

Returns:

  • (Array<Location>)

    the full set of backtrace lines parsed as Location instances



31
32
33
34
35
# File 'lib/minitest/heat/backtrace.rb', line 31

def locations
  return [] if raw_backtrace.nil?

  @locations ||= raw_backtrace.map { |entry| Backtrace::LineParser.read(entry) }
end

#project_locationsArray<Location>

All entries from the backtrace that are files within the project

Returns:

  • (Array<Location>)

    the backtrace lines from within the project



48
49
50
# File 'lib/minitest/heat/backtrace.rb', line 48

def project_locations
  @project_locations ||= locations.select(&:project_file?)
end

#recently_modified_locationsArray<Location>

All entries from the backtrace within the project and sorted with the most recently modified

files at the beginning

Returns:

  • (Array<Location>)

    the sorted backtrace lines from the project



41
42
43
# File 'lib/minitest/heat/backtrace.rb', line 41

def recently_modified_locations
  @recently_modified_locations ||= project_locations.sort_by(&:mtime).reverse
end

#source_code_locationsArray<Location>

All source code entries from the backtrace (i.e. excluding tests)

Returns:

  • (Array<Location>)

    the backtrace lines from within the source code



62
63
64
# File 'lib/minitest/heat/backtrace.rb', line 62

def source_code_locations
  @source_code_locations ||= project_locations.select(&:source_code_file?)
end

#test_locationsArray<Location>

All entries from the backtrace within the project tests

Returns:

  • (Array<Location>)

    the backtrace lines from within the tests



55
56
57
# File 'lib/minitest/heat/backtrace.rb', line 55

def test_locations
  @test_locations ||= project_locations.select(&:test_file?)
end