Skip to content

Commit

Permalink
Merge pull request #11030 from mjtko/fix/backtrace-silencer-noise-wit…
Browse files Browse the repository at this point in the history
…h-multiple-silencers

Fix BacktraceSilencer#noise when multiple silencers are configured
  • Loading branch information
drogus committed Jun 21, 2013
2 parents a29f746 + a3678e4 commit 3c0ef05
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Fix return value from `BacktraceCleaner#noise` when the cleaner is configured
with multiple silencers.

Fixes #11030

*Mark J. Titorenko*

* `HashWithIndifferentAccess#select` now returns a `HashWithIndifferentAccess`
instance instead of a `Hash` instance.

Expand Down
6 changes: 1 addition & 5 deletions activesupport/lib/active_support/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ def silence(backtrace)
end

def noise(backtrace)
@silencers.each do |s|
backtrace = backtrace.select { |line| s.call(line) }
end

backtrace
backtrace - silence(backtrace)
end
end
end
21 changes: 21 additions & 0 deletions activesupport/test/clean_backtrace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ def setup
end
end

class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase
def setup
@bc = ActiveSupport::BacktraceCleaner.new
@bc.add_silencer { |line| line =~ /mongrel/ }
@bc.add_silencer { |line| line =~ /yolo/ }
end

test "backtrace should not contain lines that match the silencers" do
assert_equal \
[ "/other/class.rb" ],
@bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb", "/other/yolo.rb" ])
end

test "backtrace should only contain lines that match the silencers" do
assert_equal \
[ "/mongrel/class.rb", "/mongrel/stuff.rb", "/other/yolo.rb" ],
@bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb", "/other/yolo.rb" ],
:noise)
end
end

class BacktraceCleanerFilterAndSilencerTest < ActiveSupport::TestCase
def setup
@bc = ActiveSupport::BacktraceCleaner.new
Expand Down

0 comments on commit 3c0ef05

Please sign in to comment.