How to show longer runs in Rails TestCases

Is there a set configuration variable or some other way to get Rails ActiveSupport::TestCase to display a string of more than one ? 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 
+6
ruby unit-testing ruby-on-rails-3
source share
4 answers

See if the 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 shorten paths, and silencers remove some lines from the backtrace.

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

+27
source share

You can configure traces of the Minitest stack, 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 takes the full stack trace in the bt parameter as an array and returns the filtered array. If you want the whole stack to show just pass the input:

 class MyBacktraceFilter def filter bt bt end end MiniTest.backtrace_filter = MyBacktraceFilter.new 
+2
source share

You can try setting the global variable $ DEBUG to a value other than zero. If this minitest that filters your backtrace, setting $DEBUG = true ensures that the entire backtrace is printed.

+1
source share

You can try to wrap the error code as follows:

 begin # failing code rescue Exception => e puts e.message puts e.backtrace end 

Another way is to debug your application using ruby-debug .

+1
source share

All Articles