Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show longer traces in Rails TestCases

Is there a config variable to set, or some other way to get Rails ActiveSupport::TestCase to show more than one trace line? It is really hard to debug otherwise.

Example:

ERROR test_something (0.73s) 
      SystemStackError: stack level too deep
      /Users/mario/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.9/lib/active_record/connection_adapters/abstract/database_statements.rb:153
like image 949
Mario Uher Avatar asked Aug 02 '11 07:08

Mario Uher


2 Answers

See whether you haven't a file config/initializers/backtrace_silencers.rb

It says:

# You can also remove all the silencers if you're trying to debug
# a problem that might stem from framework code.
Rails.backtrace_cleaner.remove_silencers!

You can also call remove_filters! if the first was not enough, but filters only make the paths shorter, while silencers do remove some lines from the backtrace.

You may find the source code in railties/lib/rails/backtrace_cleaner.rb and activesupport/lib/active_support/backtrace_cleaner.rb useful.

like image 132
Arsen7 Avatar answered Oct 29 '22 19:10

Arsen7


You can customize Minitest stack traces like this for example:

class MyBacktraceFilter
  def filter bt
    bt.dup.reject{|x| not x.to_s =~ /#{::Rails.root.to_s}/}
  end
end
MiniTest.backtrace_filter = MyBacktraceFilter.new

The filter method accepts the full stack trace in the bt parameter as an array and returns the filtered array. If you want the entire stack to show simply pass the input:

class MyBacktraceFilter
  def filter bt
    bt
  end
end
MiniTest.backtrace_filter = MyBacktraceFilter.new
like image 41
bbozo Avatar answered Oct 29 '22 21:10

bbozo