Class: RSpec::Core::BacktraceFormatter

### Home Classes Methods

### In Files

- lib/rspec/core/backtrace_formatter.rb

### Parent

Object

### Methods

- ::new
- #backtrace_line
- #exclude?
- #filter_gem
- #format_backtrace
- #full_backtrace?

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::AnonymousExampleGroup
- RSpec::Core::Backports
- RSpec::Core::Backports::Random
- RSpec::Core::Backports::Random::Implementation
- RSpec::Core::Backports::Random::MT19937
- RSpec::Core::BacktraceFormatter
- RSpec::Core::Configuration
- RSpec::Core::Configuration::DeprecationReporterBuffer
- RSpec::Core::Configuration::ExposeCurrentExample
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::DRbOptions
- RSpec::Core::DRbRunner
- RSpec::Core::DSL
- RSpec::Core::DSL::RSpec
- RSpec::Core::Example
- RSpec::Core::Example::ExecutionResult
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::ExclusionRules
- RSpec::Core::FilterManager
- RSpec::Core::FilterRules
- RSpec::Core::FilterableItemRepository
- RSpec::Core::FilterableItemRepository::QueryOptimized
- RSpec::Core::FilterableItemRepository::UpdateOptimized
- RSpec::Core::FlatMap
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::ConsoleCodes
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DeprecationFormatter::DelayedPrinter
- RSpec::Core::Formatters::DeprecationFormatter::FileStream
- RSpec::Core::Formatters::DeprecationFormatter::ImmediatePrinter
- RSpec::Core::Formatters::DeprecationFormatter::RaiseErrorStream
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::Loader
- RSpec::Core::Formatters::ProfileFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::Protocol
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::CoderayConverter
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::HashImitatable
- RSpec::Core::HashImitatable::ClassMethods
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterContextHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollections
- RSpec::Core::InclusionRules
- RSpec::Core::LegacyExampleGroupHash
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::After
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::Before
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleGroupHash
- RSpec::Core::Metadata::ExampleHash
- RSpec::Core::Metadata::HashPopulator
- RSpec::Core::MetadataFilter
- RSpec::Core::MinitestAssertionsAdapter
- RSpec::Core::MockingAdapters
- RSpec::Core::MockingAdapters::Flexmock
- RSpec::Core::MockingAdapters::Mocha
- RSpec::Core::MockingAdapters::Null
- RSpec::Core::MockingAdapters::RR
- RSpec::Core::MockingAdapters::RSpec
- RSpec::Core::Notifications
- RSpec::Core::Notifications::DeprecationNotification
- RSpec::Core::Notifications::ExampleNotification
- RSpec::Core::Notifications::ExamplesNotification
- RSpec::Core::Notifications::FailedExampleNotification
- RSpec::Core::Notifications::NullColorizer
- RSpec::Core::Notifications::NullNotification
- RSpec::Core::Notifications::PendingExampleFailedAsExpectedNotification
- RSpec::Core::Notifications::PendingExampleFixedNotification
- RSpec::Core::Notifications::PendingExampleNotificationMethods
- RSpec::Core::Notifications::ProfileNotification
- RSpec::Core::Notifications::SeedNotification
- RSpec::Core::Notifications::SkippedExampleNotification
- RSpec::Core::Notifications::SummaryNotification
- RSpec::Core::NullReporter
- RSpec::Core::Ordering
- RSpec::Core::Ordering::ConfigurationManager
- RSpec::Core::Ordering::Custom
- RSpec::Core::Ordering::Identity
- RSpec::Core::Ordering::Random
- RSpec::Core::Ordering::Registry
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::Pending::SkipDeclaredInExample
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::RandomNumberGenerator
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::Sandbox
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::SharedExampleGroupInclusionStackFrame
- RSpec::Core::SharedExampleGroupModule
- RSpec::Core::SuiteHookContext
- RSpec::Core::TestUnitAssertionsAdapter
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::Warnings
- RSpec::Core::World
- RSpec::ExampleGroups
- Object

No matching classes.

# RSpec::Core::BacktraceFormatter

@private

### Attributes

exclusion_patterns[RW]

@private

full_backtrace[W]
inclusion_patterns[RW]

@private

### Public Class Methods

new() click to toggle source

    # File lib/rspec/core/backtrace_formatter.rb, line 8
    def initialize
      @full_backtrace = false

      patterns = ] /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

### Public Instance Methods

backtrace_line(line) click to toggle source

    # File lib/rspec/core/backtrace_formatter.rb, line 48
    def backtrace_line(line)
      Metadata.relative_path(line) unless exclude?(line)
    rescue SecurityError
      nil
    end

exclude?(line) click to toggle source

    # File lib/rspec/core/backtrace_formatter.rb, line 54
    def exclude?(line)
      return false if @full_backtrace
      matches?(exclusion_patterns, line) && !matches?(inclusion_patterns, line)
    end

filter_gem(gem_name) click to toggle source

    # File lib/rspec/core/backtrace_formatter.rb, line 28
    def filter_gem(gem_name)
      sep = File::SEPARATOR
      exclusion_patterns << /#{sep}#{gem_name}(-[^#{sep}]+)?#{sep}/
    end

format_backtrace(backtrace, options={}) click to toggle source

    # File lib/rspec/core/backtrace_formatter.rb, line 33
    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

full_backtrace?() click to toggle source

    # File lib/rspec/core/backtrace_formatter.rb, line 24
    def full_backtrace?
      @full_backtrace || exclusion_patterns.empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.