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

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ CommonBacktraceTruncater

Returns a new instance of CommonBacktraceTruncater.



397
398
399
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 397

def initialize(parent)
  @parent = parent
end

Instance Method Details

#with_truncated_backtrace(child) ⇒ Object



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 401

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