Sha256: ed6d746d09435c35ab483b0a38cc036299da0a3a7d4bac9fad62cc6fd9aacaac

Contents?: true

Size: 1.93 KB

Versions: 33

Compression:

Stored size: 1.93 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 ]
        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 backtrace if options[:full_backtrace]

        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)
      rescue SecurityError
        nil
      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

33 entries across 32 versions & 8 rubygems

Version Path
opal-rspec-0.8.0 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.8.0.alpha3 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.8.0.alpha2 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.8.0.alpha1 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.7.1 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.7.0 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.6.2 rspec-core/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.7.0.rc.2 rspec-core/upstream/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.6.1 rspec-core/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.6.0 rspec-core/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.6.0.beta1 rspec-core/lib/rspec/core/backtrace_formatter.rb
opal-connect-rspec-0.5.0 rspec-core/lib/rspec/core/backtrace_formatter.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.5.0 rspec-core/lib/rspec/core/backtrace_formatter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-core-3.1.7/lib/rspec/core/backtrace_formatter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/backtrace_formatter.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-core-3.1.7/lib/rspec/core/backtrace_formatter.rb
suzuko-0.1.8 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.2.3/lib/rspec/core/backtrace_formatter.rb
suzuko-0.1.7 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.2.3/lib/rspec/core/backtrace_formatter.rb
opal-rspec-0.5.0.beta3 rspec-core/lib/rspec/core/backtrace_formatter.rb