public
Rubygem
Description: Suppresses the noise in your Test::Unit backtraces
Homepage: http://www.thoughtbot.com/projects/quietbacktrace
Clone URL: git://github.com/thoughtbot/quietbacktrace.git
dancroak (author)
Sat Jun 07 12:23:47 -0700 2008
commit  8ff1df35636d7b318e60b415f1f21b240610ccb4
tree    09ab4759c2a1433688273251efb2ac8e5f379d41
parent  50e8aa8dac4dfe97225ba7f6b8e052af0beeeb2d
name age message
file MIT-LICENSE Thu Nov 29 17:28:05 -0800 2007 baby steps toward turning this sucker into a gem [dcroak]
file README.markdown Sat Jun 07 12:04:03 -0700 2008 updating README to use markdown [dancroak]
file Rakefile Sat Jun 07 12:18:53 -0700 2008 fixing bug in Rakefile, renaming quiet_backtrac... [dancroak]
directory lib/ Sat Jun 07 12:23:47 -0700 2008 adding new silencer for Ruby framework on Leopard [dancroak]
directory test/ Sat Jun 07 12:14:51 -0700 2008 adding Rakefile [dancroak]
README.markdown

Quiet Backtrace

Quiet Backtrace suppresses the noise in your Test::Unit backtrace. It also provides hooks for you to add additional silencers and filters.

Install

sudo gem install quietbacktrace

Usage

Quiet Backtrace works by adding new attributes to Test::Unit::TestCase. By default, their values are:

self.quiet_backtrace = true
self.backtrace_silencers = [:test_unit, :gem_root, :e1]
self.backtrace_filters = [:method_name]

Silencers remove lines from the backtrace that return true for given conditions. Filters modify the output of backtrace lines.

Override the defaults by adding your own backtrace_silencers:

class Test::Unit::TestCase
  self.new_backtrace_silencer :shoulda do |line| 
    line.include? 'vendor/plugins/shoulda'
  end
  self.backtrace_silencers << :shoulda
end

Or your own backtrace_filters:

class Test::Unit::TestCase
  self.new_backtrace_filter :ruby_path do |line|
     ruby_file_path = '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8'
     line.slice!(0..(line =~ ruby_file_path)) if (line =~ ruby_file_path)
  end
  self.backtrace_filters << :ruby_path
end

Turn Quiet Backtrace off anywhere in your test suite by setting the flag to false:

Test::Unit::TestCase.quiet_backtrace = false

Rails-specific usage

Install the gem and add it your Rails app:

  • gem install thoughtbot-quietbacktrace --source http://gems.github.com
  • cd vendor/gems
  • gem unpack quietbacktrace

Quiet Backtrace comes with an excellent Rails-specific silencer and filter. They must be added (usually in test_helper.rb) because they are not turned on by default:

class Test::Unit::TestCase
  self.backtrace_silencers << :rails_vendor
  self.backtrace_filters   << :rails_root
end

Because Quiet Backtrace works by adding attributes onto Test::Unit::TestCase, you can add and remove silencers and filters at any level in your test suite, down to the individual test.

Requirements

  • Test::Unit
  • aliasing.rb and attribute_accessors.rb, which are sniped from ActiveSupport and are included in the gem. They allow quietbacktrace.rb to use alias method chain, cattr accessor, and mattr accessor.

Resources

Authors

Special thanks to the Boston.rb group for cultivating this idea at our inaugural hackfest.

Copyright (c) Dan Croak, James Golick, Joe Ferris, thoughtbot, inc. (the MIT license)