Class: Cucumber::Formatter::BacktraceFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/formatter/backtrace_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ BacktraceFilter

Returns a new instance of BacktraceFilter.



30
31
32
# File 'lib/cucumber/formatter/backtrace_filter.rb', line 30

def initialize(exception)
  @exception = exception
end

Instance Method Details

#exceptionObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cucumber/formatter/backtrace_filter.rb', line 34

def exception
  return @exception if ::Cucumber.use_full_backtrace

  pwd_pattern = /#{::Regexp.escape(::Dir.pwd)}\//m
  backtrace = @exception.backtrace.map { |line| line.gsub(pwd_pattern, './') }

  filtered = (backtrace || []).reject do |line|
    line =~ BACKTRACE_FILTER_PATTERNS
  end

  if ::ENV['CUCUMBER_TRUNCATE_OUTPUT']
    # Strip off file locations
    filtered = filtered.map do |line|
      line =~ /(.*):in `/ ? Regexp.last_match(1) : line
    end
  end

  @exception.set_backtrace(filtered)
  @exception
end