在Ruby on Rails TestCase中启用完整的回溯

我运行时只显示一行回溯:

rake test 

输出:

 ERROR should get search for keywords (1.93s) NoMethodError: undefined method `features' for # /usr/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:385:in `method_missing' 

我需要更多的回溯信息。 我试过了

  • rake test –trace

  • Rails.backtrace_cleaner.remove_silencers! 在config / initializers / backtrace_silencers.rb中

  • 设置全局$ DEBUG = true

它不起作用。

我怎么才能打开它?

 BACKTRACE=blegga rake test BACKTRACE=blegga rails test # rails 5+ 

如果需要与rake相关的日志,请追加--trace

终于搞清楚了。 问题在于Rails 3.1中包含’turn’gem,或实际上是转向v0.8.2,这是默认Gemfile所要求的:

 group :test do # Pretty printed test output gem 'turn', '0.8.2', require: false end 

转v0.8.2不包括完整的回溯,所以你必须升级才能得到它。 我通过将我的Gemfile中的上述内容更改为:

 group :test do # Pretty printed test output gem 'turn', require: false gem 'minitest' end 

(我不得不添加minitest,否则会抛出一个RuntimeError,说“MiniTest v1.6.0已经过时了。”)

然后我运行了bundle update turn并获得了最新版本(截至本文撰写时为0.9.2)。 这给了完整的回溯。