# Suggestion for filtering your stack traces with Test::Unit::

**URL:** <https://www.ruby-forum.com/t/suggestion-for-filtering-your-stack-traces-with-test/110038>\
**Category:** Rails\
**Created:** [July 21, 2007, 9:28pm UTC](https://www.ruby-forum.com/t/suggestion-for-filtering-your-stack-traces-with-test/110038 "2007-07-21T21:28:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [July 21, 2007, 9:28pm UTC](https://www.ruby-forum.com/t/suggestion-for-filtering-your-stack-traces-with-test/110038/1 "2007-07-21T21:28:21Z")

</div>

Most of the time, I don’t want to see the whole stack trace including  
the environment - I just want to see my code. So, I tossed this in my  
test:

module Test  
module Unit  
module Util  
module BacktraceFilter  
def filter\_backtrace\_with\_only\_my\_code(backtrace, prefix=nil)  
result = filter\_backtrace\_without\_only\_my\_code backtrace,  
prefix  
result.reject! {|x| x =~ /ruby.lib.ruby/}  
result.reject! {|x| x =~ /vendor.plugins.mocha/}  
result  
end  
alias\_method\_chain :filter\_backtrace, :only\_my\_code  
end  
end  
end  
end

## You’ll probably want to play around with what gets filtered in and out. I think of this sort of thing as more of a debugger macro than actual code; it gets changed constantly depending on what I’m doing.

James M. | removed\_email\_address@domain.invalid  
Ruby and Ruby on Rails consulting  
[blog.restphone.com](http://blog.restphone.com)

---

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [July 25, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/suggestion-for-filtering-your-stack-traces-with-test/110038/2 "2007-07-25T18:29:45Z")

</div>

Hi James,

> Most of the time, I don’t want to see the whole stack trace including  
> the environment - I just want to see my code. So, I tossed this in my  
> test:  
> [snip]  
> You’ll probably want to play around with what gets filtered in and  
> out. I think of this sort of thing as more of a debugger macro than  
> actual code; it gets changed constantly depending on what I’m doing.

That looks really useful. Thanks.

I felt the same way when running tests using Autotest and came up  
with a similar solution, though mine’s confined to Autotest:

[http://blog.airbladesoftware.com/2007/3/22/filtering-autotest-s-output](http://blog.airbladesoftware.com/2007/3/22/filtering-autotest-s-output)

Regards,  
Andy S.
