The Rails Backtrace cleaner

Posted by dave
on Monday, November 23

I’d missed it, but Rails now incorporates the functionality previously provided by Thoughtbot’s quietbacktrace gem. It’s pretty easy to use, too. By default, it whacks all of the stacktrace garbage that used to happen in a Rails 2.2 app. It’s also possible to easily add new filters in your test_helper.rb file, e.g.

  # Add more helper methods to be used by all tests here...
  #
  Rails.backtrace_cleaner.add_silencer { |line| line =~ /lib\/shoulda/ }

Artificially inducing a test failure then gives a beautiful little stack trace, like so:

  1) Failure:
test: the JobsController should get new. (JobsControllerTest) [/test/functional/jobs_controller_test.rb:19]:
Expected response to be a <:successsadfsdaf>, but was <200>