diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-22 18:06:08 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-22 18:06:08 +0100 |
commit | f42c77f927eb49b00e84d355e07de48723d03fcb (patch) | |
tree | 2a459814a9708f292c99e9c5e99dd41d2d801353 /activesupport/test | |
parent | a026b4c983681b71d876ea37958c3e5bc605acac (diff) | |
download | rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.gz rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.bz2 rails-f42c77f927eb49b00e84d355e07de48723d03fcb.zip |
Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH]
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/abstract_unit.rb | 1 | ||||
-rw-r--r-- | activesupport/test/clean_backtrace_test.rb | 47 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 2 |
3 files changed, 49 insertions, 1 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index deb512eeb6..047f0effad 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -3,6 +3,7 @@ require 'test/unit' gem 'mocha', '>= 0.9.0' require 'mocha' +$:.unshift "#{File.dirname(__FILE__)}/../lib" require 'active_support' require 'active_support/test_case' diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb new file mode 100644 index 0000000000..ddbc258df1 --- /dev/null +++ b/activesupport/test/clean_backtrace_test.rb @@ -0,0 +1,47 @@ +require 'abstract_unit' + +class BacktraceCleanerFilterTest < ActiveSupport::TestCase + def setup + @bc = ActiveSupport::BacktraceCleaner.new + @bc.add_filter { |line| line.gsub("/my/prefix", '') } + end + + test "backtrace should not contain prefix when it has been filtered out" do + assert_equal "/my/class.rb", @bc.clean([ "/my/prefix/my/class.rb" ]).first + end + + test "backtrace should contain unaltered lines if they dont match a filter" do + assert_equal "/my/other_prefix/my/class.rb", @bc.clean([ "/my/other_prefix/my/class.rb" ]).first + end + + test "backtrace should filter all lines in a backtrace" do + assert_equal \ + ["/my/class.rb", "/my/module.rb"], + @bc.clean([ "/my/prefix/my/class.rb", "/my/prefix/my/module.rb" ]) + end +end + +class BacktraceCleanerSilencerTest < ActiveSupport::TestCase + def setup + @bc = ActiveSupport::BacktraceCleaner.new + @bc.add_silencer { |line| line =~ /mongrel/ } + end + + test "backtrace should not contain lines that match the silencer" do + assert_equal \ + [ "/other/class.rb" ], + @bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb" ]) + end +end + +class BacktraceCleanerFilterAndSilencerTest < ActiveSupport::TestCase + def setup + @bc = ActiveSupport::BacktraceCleaner.new + @bc.add_filter { |line| line.gsub("/mongrel", "") } + @bc.add_silencer { |line| line =~ /mongrel/ } + end + + test "backtrace should not silence lines that has first had their silence hook filtered out" do + assert_equal [ "/class.rb" ], @bc.clean([ "/mongrel/class.rb" ]) + end +end
\ No newline at end of file diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 32cab2724b..d3edbc6826 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -21,7 +21,7 @@ class ArrayExtAccessTests < Test::Unit::TestCase assert_equal array[2], array.third assert_equal array[3], array.fourth assert_equal array[4], array.fifth - assert_equal array[41], array.fourty_two + assert_equal array[41], array.forty_two end end |