Class: RSpec::Core::BacktraceCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/backtrace_cleaner.rb

Constant Summary collapse

DEFAULT_EXCLUSION_PATTERNS =
[
  /\/lib\d*\/ruby\//,
  /org\/jruby\//,
  /bin\//,
  %r|/gems/|,
  /spec\/spec_helper\.rb/,
  /lib\/rspec\/(core|expectations|matchers|mocks)/
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inclusion_patterns = nil, exclusion_patterns = DEFAULT_EXCLUSION_PATTERNS.dup) ⇒ BacktraceCleaner

Returns a new instance of BacktraceCleaner.



17
18
19
20
21
22
23
24
25
# File 'lib/rspec/core/backtrace_cleaner.rb', line 17

def initialize(inclusion_patterns=nil, exclusion_patterns=DEFAULT_EXCLUSION_PATTERNS.dup)
  @exclusion_patterns = exclusion_patterns

  if inclusion_patterns.nil?
    @inclusion_patterns = (matches_an_exclusion_pattern? Dir.getwd) ? [Regexp.new(Dir.getwd)] : []
  else
    @inclusion_patterns = inclusion_patterns
  end
end

Instance Attribute Details

#exclusion_patternsObject

Returns the value of attribute exclusion_patterns.



15
16
17
# File 'lib/rspec/core/backtrace_cleaner.rb', line 15

def exclusion_patterns
  @exclusion_patterns
end

#inclusion_patternsObject

Returns the value of attribute inclusion_patterns.



14
15
16
# File 'lib/rspec/core/backtrace_cleaner.rb', line 14

def inclusion_patterns
  @inclusion_patterns
end

Instance Method Details

#exclude?(line) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rspec/core/backtrace_cleaner.rb', line 27

def exclude?(line)
  @inclusion_patterns.none? {|p| line =~ p} and matches_an_exclusion_pattern?(line)
end

#full_backtrace=(true_or_false) ⇒ Object



31
32
33
# File 'lib/rspec/core/backtrace_cleaner.rb', line 31

def full_backtrace=(true_or_false)
  @exclusion_patterns = true_or_false ? [] : DEFAULT_EXCLUSION_PATTERNS.dup
end

#full_backtrace?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rspec/core/backtrace_cleaner.rb', line 35

def full_backtrace?
  @exclusion_patterns.empty?
end