class RSpec::Core::Formatters::ExceptionPresenter::Factory::CommonBacktraceTruncater

@private

Public Class Methods

# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 424
def initialize(parent)
  @parent = parent
end

Public Instance Methods

# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 428
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.nil?
  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