Class: Whitestone::Output::BacktraceProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/whitestone/output.rb

Constant Summary collapse

INTERNALS_RE =
(
  libdir = File.dirname(__FILE__)
  bindir = "bin/whitestone"
  Regexp.union(libdir, bindir)
)

Instance Method Summary collapse

Constructor Details

#initialize(backtrace, filter_yn) ⇒ BacktraceProcessor

Returns a new instance of BacktraceProcessor.



265
266
267
# File 'lib/whitestone/output.rb', line 265

def initialize(backtrace, filter_yn)
  @backtrace = filter(backtrace, filter_yn)
end

Instance Method Details

#backtraceObject

Returns the backtrace (array of strings) with all paths converted to relative paths (where possible).



305
306
307
# File 'lib/whitestone/output.rb', line 305

def backtrace
  make_relative(@backtrace)
end

#determine_file_and_lineno(calls = nil) ⇒ Object

calls is an array of proc objects (scopes of the tests run so far, from top level to current nesting). The last of them is the context for the current test, like

#<Proc:0x10b7b1b8@./test/shape/triangle/construct/various.rb:52>

From this, we determine the current test file. Then we look in the backtrace for the last mention of that test file. That stack frame, from the backtrace, tells us what line of code in the test file caused the failure/error.

If calls is not provided, we simply take the first frame of the backtrace. That will happen when reporting a failure. A failure is simply a false assertion, so no stack unwinding is necessary.

If no appropriate frame is found (not sure why that would be), then the return values will be nil.

Return

file (String) and line number (Integer)



288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/whitestone/output.rb', line 288

def determine_file_and_lineno(calls=nil)
  frame =
    if calls
      current_test_file = calls.last.to_s.scan(/@(.+?):/).flatten.first
      @backtrace.find { |str| str.index(current_test_file) }
    else
      @backtrace.first
    end
  file, line =
    if frame
      file, line = frame.scan(/(.+?):(\d+(?=:|\z))/).first
      [file, line.to_i]
    end
end