Sha256: 504a22924897c95714777cbfa60bd1625c93ea16fe9f882f13b83fc5e322d338

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 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/
      site_ruby/
      minitest
      test/unit
      .gem/ruby
      bin/bundle
      rdebug-ide
    ]

    @backtrace_filters << RbConfig::CONFIG['rubyarchdir'] if RbConfig::CONFIG['rubyarchdir']
    @backtrace_filters << RbConfig::CONFIG['rubylibdir'] if RbConfig::CONFIG['rubylibdir']

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

    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 # rubocop:disable Style/RegexpLiteral
        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
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-7.1.0/lib/cucumber/formatter/backtrace_filter.rb
cucumber-7.1.0 lib/cucumber/formatter/backtrace_filter.rb
cucumber-7.0.0 lib/cucumber/formatter/backtrace_filter.rb
cucumber-6.1.0 lib/cucumber/formatter/backtrace_filter.rb
cucumber-6.0.0 lib/cucumber/formatter/backtrace_filter.rb