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.



14
15
16
# File 'lib/cucumber/formatter/backtrace_filter.rb', line 14

def initialize(exception)
  @exception = exception
end

Instance Method Details

#exceptionObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber/formatter/backtrace_filter.rb', line 18

def exception
  return @exception if ::Cucumber.use_full_backtrace

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

  filtered = (@exception.backtrace || []).reject do |line|
    BACKTRACE_FILTER_PATTERNS.detect { |p| line =~ p }
  end

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

  @exception.set_backtrace(filtered)
  @exception
end