Skip to content
Browse files

Pull backtrace cleaning behaviour into the backtrace_cleaner object

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information...
1 parent 7908058 commit 0eb2545eed56e1a5468b2dc761b7277a890e4072 @samphippen committed
Showing with 23 additions and 27 deletions.
  1. +15 −1 lib/rspec/core/backtrace_cleaner.rb
  2. +8 −26 lib/rspec/core/configuration.rb
View
16 lib/rspec/core/backtrace_cleaner.rb
@@ -2,10 +2,20 @@ module RSpec
module Core
class BacktraceCleaner
+ DEFAULT_INCLUDE_PATTERNS = [Regexp.new(Dir.getwd)]
+ DEFAULT_EXCLUDE_PATTERNS = [
+ /\/lib\d*\/ruby\//,
+ /org\/jruby\//,
+ /bin\//,
+ %r|/gems/|,
+ /spec\/spec_helper\.rb/,
+ /lib\/rspec\/(core|expectations|matchers|mocks)/
+ ]
+
attr_accessor :include_patterns
attr_accessor :exclude_patterns
- def initialize(include_patterns, exclude_patterns)
+ def initialize(include_patterns=DEFAULT_INCLUDE_PATTERNS, exclude_patterns=DEFAULT_EXCLUDE_PATTERNS.dup)
@include_patterns = include_patterns
@exclude_patterns = exclude_patterns
end
@@ -13,6 +23,10 @@ def initialize(include_patterns, exclude_patterns)
def exclude?(line)
@include_patterns.none? {|p| line =~ p} and @exclude_patterns.any? {|p| line =~ p}
end
+
+ def full_backtrace=(true_or_false)
+ @exclude_patterns = true_or_false ? [] : DEFAULT_EXCLUDE_PATTERNS
+ end
end
end
end
View
34 lib/rspec/core/configuration.rb
@@ -185,15 +185,6 @@ def self.add_setting(name, opts={})
# @private
attr_accessor :filter_manager
- DEFAULT_BACKTRACE_PATTERNS = [
- /\/lib\d*\/ruby\//,
- /org\/jruby\//,
- /bin\//,
- %r|/gems/|,
- /spec\/spec_helper\.rb/,
- /lib\/rspec\/(core|expectations|matchers|mocks)/
- ]
-
attr_reader :backtrace_cleaner
def initialize
@@ -206,9 +197,7 @@ def initialize
@pattern = '**/*_spec.rb'
@failure_exit_code = 1
- @backtrace_exclude_patterns = DEFAULT_BACKTRACE_PATTERNS.dup
- @backtrace_include_patterns = [Regexp.new(Dir.getwd)]
- recreate_backtrace_cleaner
+ @backtrace_cleaner = BacktraceCleaner.new
@default_path = 'spec'
@filter_manager = FilterManager.new
@@ -298,32 +287,29 @@ def mock_framework=(framework)
def backtrace_clean_patterns
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
"RSpec::Core::Configuration#backtrace_exclude_patterns")
- backtrace_exclude_patterns
+ @backtrace_cleaner.exclude_patterns
end
def backtrace_clean_patterns=(patterns)
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
"RSpec::Core::Configuration#backtrace_exclude_patterns")
- backtrace_exclude_patterns = patterns
- recreate_backtrace_cleaner
+ @backtrace_cleaner.exclude_patterns = patterns
end
def backtrace_include_patterns
- @backtrace_include_patterns
+ @backtrace_cleaner.include_patterns
end
def backtrace_include_patterns=(patterns)
- @backtrace_include_patterns = patterns
- recreate_backtrace_cleaner
+ @backtrace_cleaner.include_patterns = patterns
end
def backtrace_exclude_patterns
- @backtrace_exclude_patterns
+ @backtrace_cleaner.exclude_patterns
end
def backtrace_exclude_patterns=(patterns)
- @backtrace_exclude_patterns = patterns
- recreate_backtrace_cleaner
+ @backtrace_cleaner.exclude_patterns = patterns
end
# Sets the mock framework adapter module.
@@ -455,7 +441,7 @@ def expect_with(*frameworks)
end
def full_backtrace=(true_or_false)
- @backtrace_exclude_patterns = true_or_false ? [] : DEFAULT_BACKTRACE_PATTERNS
+ @backtrace_cleaner.full_backtrace = true_or_false
end
def color(output=output_stream)
@@ -972,10 +958,6 @@ def order_groups_and_examples(&block)
private
- def recreate_backtrace_cleaner
- @backtrace_cleaner = BacktraceCleaner.new(@backtrace_include_patterns, @backtrace_exclude_patterns)
- end
-
def get_files_to_run(paths)
patterns = pattern.split(",")
paths.map do |path|

0 comments on commit 0eb2545

Please sign in to comment.
Something went wrong with that request. Please try again.