How to get stack trace from a Test::Unit::TestCase How to get stack trace from a Test::Unit::TestCase ruby ruby

How to get stack trace from a Test::Unit::TestCase


Looking through the code of Test::Unit in Ruby 1.8, it seems all the errors go through the Test::Unit::Error object which filters the backtrace in its #long_display method. There is no configuration and all runners will use the same filtered trace.

Brute force monkey patch to get the whole trace: (I put this in my single test case file; perhaps you could put it in a test helper)

require 'test/unit/util/backtracefilter'module Test::Unit::Util::BacktraceFilter  def filter_backtrace(backtrace, prefix=nil)    backtrace  endend

And monkey patch for Ruby 1.9 (which uses minitest)

def MiniTest.filter_backtrace(bt)  btend


Use this anywhere in you class to get full stack trace. I used it in my unit test case to debug my test class.

rescue => eputs e.inspectputs e.backtrace