class RSpec::Core::BacktraceFormatter

@private

def backtrace_line(line)

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

def exclude?(line)

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

def filter_gem(gem_name)

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

def format_backtrace(backtrace, options={})

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 full_backtrace?

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

def initialize

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

def matches?(patterns, line)

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