Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change the default inclusion behaviour of the backtrace cleaner

By default the current working directory will only be included if it
matches one of the exclusion patterns

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information...
commit 59114549e007603606163c45a9a96624141b42be 1 parent 6c23e85
@samphippen authored
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/rspec/core/backtrace_cleaner.rb
View
19 lib/rspec/core/backtrace_cleaner.rb
@@ -2,7 +2,6 @@ module RSpec
module Core
class BacktraceCleaner
- DEFAULT_INCLUSION_PATTERNS = [Regexp.new(Dir.getwd)]
DEFAULT_EXCLUSION_PATTERNS = [
/\/lib\d*\/ruby\//,
/org\/jruby\//,
@@ -15,18 +14,30 @@ class BacktraceCleaner
attr_accessor :inclusion_patterns
attr_accessor :exclusion_patterns
- def initialize(inclusion_patterns=DEFAULT_INCLUSION_PATTERNS.dup, exclusion_patterns=DEFAULT_EXCLUSION_PATTERNS.dup)
- @inclusion_patterns = inclusion_patterns
+ 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
def exclude?(line)
- @inclusion_patterns.none? {|p| line =~ p} and @exclusion_patterns.any? {|p| line =~ p}
+ @inclusion_patterns.none? {|p| line =~ p} and matches_an_exclusion_pattern?(line)
end
def full_backtrace=(true_or_false)
@exclusion_patterns = true_or_false ? [] : DEFAULT_EXCLUSION_PATTERNS.dup
end
+
+ private
+
+ def matches_an_exclusion_pattern?(line)
+ @exclusion_patterns.any? {|p| line =~ p}
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.