Class: Minitest::Heat::Output::Backtrace
- Inherits:
-
Object
- Object
- Minitest::Heat::Output::Backtrace
- Defined in:
- lib/minitest/heat/output/backtrace.rb
Overview
Builds the collection of tokens for displaying a backtrace when an exception occurs
Constant Summary collapse
- DEFAULT_INDENTATION_SPACES =
2
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#locations ⇒ Object
Returns the value of attribute locations.
Instance Method Summary collapse
-
#backtrace_locations ⇒ Array<Location>
A subset of parsed lines from the backtrace.
-
#initialize(locations) ⇒ Backtrace
constructor
A new instance of Backtrace.
-
#line_count ⇒ Integer
Determines the number of lines to display from the backtrace.
- #tokens ⇒ Object
Constructor Details
#initialize(locations) ⇒ Backtrace
Returns a new instance of Backtrace.
12 13 14 15 16 |
# File 'lib/minitest/heat/output/backtrace.rb', line 12 def initialize(locations) @locations = locations @backtrace = locations.backtrace @tokens = [] end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
10 11 12 |
# File 'lib/minitest/heat/output/backtrace.rb', line 10 def backtrace @backtrace end |
#locations ⇒ Object
Returns the value of attribute locations.
10 11 12 |
# File 'lib/minitest/heat/output/backtrace.rb', line 10 def locations @locations end |
Instance Method Details
#backtrace_locations ⇒ Array<Location>
A subset of parsed lines from the backtrace.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/minitest/heat/output/backtrace.rb', line 41 def backtrace_locations # This could eventually have additional intelligence to determine what lines are most # relevant for a given type of issue. For now, it simply takes the line numbers, but the # idea is that long-term, it could adjust that on the fly to keep the line count as low # as possible but expand it if necessary to ensure enough context is displayed. # # - If there's no clear cut details about the source of the error from within the project, # it could display the entire backtrace without filtering anything. # - It could scan the backtrace to the first appearance of project files and then display # all of the lines that occurred after that instance # - It could filter the lines differently whether the issue originated from a test or from # the source code. # - It could allow supporting a "compact" or "robust" reporter style so that someone on # a smaller screen could easily reduce the information shown so that the results could # be higher density even if it means truncating some occasionally useful details # - It could be smarter about displaying context/guidance when the full backtrace is from # outside the project's code # # But for now. It just grabs some lines. backtrace.locations.take(line_count) end |
#line_count ⇒ Integer
Determines the number of lines to display from the backtrace.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/minitest/heat/output/backtrace.rb', line 26 def line_count # Defined as a method instead of using the constant directly in order to easily support # adding options for controlling how many lines are displayed from a backtrace. # # For example, instead of a fixed number, the backtrace could dynamically calculate how # many lines it should displaye in order to get to the origination point. Or it could have # a default, but inteligently go back further if the backtrace meets some criteria for # displaying more lines. ::Minitest::Heat::Backtrace::LineCount.new(backtrace.locations).limit end |
#tokens ⇒ Object
18 19 20 21 |
# File 'lib/minitest/heat/output/backtrace.rb', line 18 def tokens # Iterate over the selected lines from the backtrace @tokens = backtrace_locations.map { |location| backtrace_location_tokens(location) } end |