Sha256: a5a78cc0ceb47e8cf42940cc49b075e5ae5088ff43aecd04b4c66b43be475d6b

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true
require 'cucumber/platform'


module Cucumber
  module Formatter
    @backtrace_filters = %w(
      /vendor/rails
      lib/cucumber
      bin/cucumber:
      lib/rspec
      gems/
      minitest
      test/unit
      .gem/ruby
      lib/ruby/
      bin/bundle
    )

    if ::Cucumber::JRUBY
      @backtrace_filters << 'org/jruby/'
    end

    BACKTRACE_FILTER_PATTERNS = Regexp.new(@backtrace_filters.join('|'))

    class BacktraceFilter
      def initialize(exception)
        @exception = exception
      end

      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 `/ ? $1 : line
          end
        end

        @exception.set_backtrace(filtered)
        @exception
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cucumber-3.1.0 lib/cucumber/formatter/backtrace_filter.rb
cucumber-3.0.2 lib/cucumber/formatter/backtrace_filter.rb
cucumber-3.0.1 lib/cucumber/formatter/backtrace_filter.rb
cucumber-3.0.0 lib/cucumber/formatter/backtrace_filter.rb
cucumber-3.0.0.pre.2 lib/cucumber/formatter/backtrace_filter.rb