Sha256: 007a7d343a88a16292d31d373c27e496c983ba4aca49543c53c243ad4b36e065

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 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_filters << '<internal:' if RUBY_ENGINE == 'truffleruby'

    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 `/ ? Regexp.last_match(1) : line
          end
        end

        @exception.set_backtrace(filtered)
        @exception
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
cucumber-9.2.1 lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.2.0 lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.1.2 lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.1.1 lib/cucumber/formatter/backtrace_filter.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.1.0 lib/cucumber/formatter/backtrace_filter.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.0.2 lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.0.1 lib/cucumber/formatter/backtrace_filter.rb
cucumber-9.0.0 lib/cucumber/formatter/backtrace_filter.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/backtrace_filter.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/backtrace_filter.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/backtrace_filter.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/backtrace_filter.rb
cucumber-8.0.0 lib/cucumber/formatter/backtrace_filter.rb