Class: RSpec::Core::Formatters::ExceptionPresenter::Factory::CommonBacktraceTruncater

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/formatters/exception_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ CommonBacktraceTruncater

Returns a new instance of CommonBacktraceTruncater



369
370
371
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 369

def initialize(parent)
  @parent = parent
end

Instance Method Details

#with_truncated_backtrace(child) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 373

def with_truncated_backtrace(child)
  child_bt  = child.backtrace
  parent_bt = @parent.backtrace
  return child if child_bt.nil? || child_bt.empty? || parent_bt.nil?

  index_before_first_common_frame = -1.downto(-child_bt.size).find do |index|
    parent_bt[index] != child_bt[index]
  end

  return child if index_before_first_common_frame == -1

  child = child.dup
  child.set_backtrace(child_bt[0..index_before_first_common_frame])
  child
end