Sha256: 0db851950e660820a68cd4f4bcbaaab31f43f2427cb441a5119fa92494c88b22

Contents?: true

Size: 1.97 KB

Versions: 7346

Compression:

Stored size: 1.97 KB

Contents

module RSpec
  module Core
    # @private
    class BacktraceFormatter
      # @private
      attr_accessor :exclusion_patterns, :inclusion_patterns

      def initialize
        @full_backtrace = false

        patterns = %w[ /lib\d*/ruby/ bin/ exe/rspec /lib/bundler/ /exe/bundle: ]
        patterns << "org/jruby/" if RUBY_PLATFORM == 'java'
        patterns.map! { |s| Regexp.new(s.gsub("/", File::SEPARATOR)) }

        @exclusion_patterns = [Regexp.union(RSpec::CallerFilter::IGNORE_REGEX, *patterns)]
        @inclusion_patterns = []

        return unless matches?(@exclusion_patterns, File.join(Dir.getwd, "lib", "foo.rb:13"))
        inclusion_patterns << Regexp.new(Dir.getwd)
      end

      attr_writer :full_backtrace

      def full_backtrace?
        @full_backtrace || exclusion_patterns.empty?
      end

      def filter_gem(gem_name)
        sep = File::SEPARATOR
        exclusion_patterns << /#{sep}#{gem_name}(-[^#{sep}]+)?#{sep}/
      end

      def format_backtrace(backtrace, options={})
        return [] unless backtrace
        return backtrace if options[:full_backtrace] || backtrace.empty?

        backtrace.map { |l| backtrace_line(l) }.compact.
          tap do |filtered|
            if filtered.empty?
              filtered.concat backtrace
              filtered << ""
              filtered << "  Showing full backtrace because every line was filtered out."
              filtered << "  See docs for RSpec::Configuration#backtrace_exclusion_patterns and"
              filtered << "  RSpec::Configuration#backtrace_inclusion_patterns for more information."
            end
          end
      end

      def backtrace_line(line)
        Metadata.relative_path(line) unless exclude?(line)
      end

      def exclude?(line)
        return false if @full_backtrace
        matches?(exclusion_patterns, line) && !matches?(inclusion_patterns, line)
      end

    private

      def matches?(patterns, line)
        patterns.any? { |p| line =~ p }
      end
    end
  end
end

Version data entries

7,346 entries across 7,264 versions & 115 rubygems

Version Path
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.5.4/lib/rspec/core/backtrace_formatter.rb
rspec-core-3.9.0 lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.5.4/lib/rspec/core/backtrace_formatter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/rspec-core-3.5.4/lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/backtrace_formatter.rb
rspec-core-3.8.2 lib/rspec/core/backtrace_formatter.rb
rspec-core-3.8.1 lib/rspec/core/backtrace_formatter.rb
nabea2-0.1.2 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/backtrace_formatter.rb
nabea2-0.1.1 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/backtrace_formatter.rb
nabea2-0.1.0 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/backtrace_formatter.rb
hatena_bookmark_client_for_ruby-0.1.3 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/backtrace_formatter.rb
hatena_bookmark_client_for_ruby-0.1.2 vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/backtrace_formatter.rb