Categories
me me me programming ruby on rails tips

Turning off the Rails 2.3.2 BacktraceCleaner

I had a situation today where, when running some functional tests, the error backtrace being displayed was not helpful at ALL. I was defining a layout for a controller as a symbol instead of a string like I should have been using. You use a string when you are just saying “Use this layout” and you use a symbol when you have a method to call that responds with the layout to use. The error I was getting was …

NoMethodError: undefined method `admin' for #<Admin::RegistrationsController>

but what was the first line that came up in the backtrace?

app/controllers/admin/registrations_controller.rb:18:in `show'

This was giving me fits. There’s no call to ‘admin’ in the ‘show’ method. I knew there had to be something else so I searched for how to see more of the backtrace.

The BacktraceCleaner introduced in Rails 2.3.2 cleans out backtrace lines coming from the Rails framework (Railties, etc). This is usually what you want. However, I was sure that my error was coming from somewhere in the framework. Turns out it’s really simple to turn off the backtrace cleaner. Add this line in a ‘setup’ method in your test_helper.rb file.

Rails.backtrace_cleaner.remove_silencers!

Very simple, very easy. My name is Chef Tell. 🙂

3 replies on “Turning off the Rails 2.3.2 BacktraceCleaner”

Sorry for the unrelated comment – just thought I’d let you know I’ve fixed some issues I had on Windows with the new ZenTest.

Basically I had two issues:
1) The old redgreen gem (i.e. not the one included in ZenTest) stopped autotest working after the first pass.
2) On Vista (and presumably on XP) snarl notifications were always passing even when there were failures.

I’ve forked redgreen here to fix the autotest issues:
http://github.com/kule/redgreen/tree/master

For Snarl to work I had to modify the failed results regular expression slightly (lib/autotest.rb) to:

self.failed_results_re = /^\s+\d+\) (?:\e\[\d+m)?(?:Failure|Error)(?:\e\[0m)?:\n(.*?)\((.*?)\)/

I’m waiting to hear back from ryan @ zentest.

Cheers
Luke

Nice fix for redgreen and Snarl. I’d been bothered by the run-once issue with autotest. I installed your gem and autotest is playing nicely now.

Thanx for the fix.

I’m gonna blog about a fix for another Snarl/Windows gotcha in a bit. The built-in Snarl plugin for autotest doesn’t allow you to double Ctrl-C to interrupt the tests. But I fixed it.

[UPDATE] not really a bug with Snarl. It turned out to be a bug with the order of my “require” lines in my .autotest file. I posted about it here.

(e)

Comments are closed.