跟踪Rails测试中的弃用警告源 [英] Trace source of deprecation warnings in rails tests
问题描述
在运行功能测试时,在其中一个测试用例中收到以下警告,但我无法查明它的来源:
When running my functional tests, I'm getting the following warning in one of the test cases but I can't pinpoint where it's coming from:
gems / actionpack-2.3.8 / lib / action_controller / record_identifier.rb:76:警告:Object#id将被弃用;使用Object#object_id
不幸的是,这是显示的回溯的唯一一行,即使我使用 rake运行它也是如此测试--trace
, log / test.log
中没有更多信息。
Unfortunately that's the only line of the backtrace that's shown, even if I run it with rake test --trace
, and there is no more information in log/test.log
.
如何获取此警告的完整回溯信息,否则找出我代码中的哪一行引起了该警告?
How can I get the full backtrace for this warning or otherwise figure out which line in my code is causing it?
推荐答案
要解决此问题,您可以启用完整的调试信息。 (请参阅帮助)
To solve this you could enable the full debugging information. (see the help)
ActiveSupport::Deprecation.debug = true
As @Eric Anderson说,应该将其放置在Rails加载之后(即在application.rb中要求'rails / all'
之后)但在捆绑程序运行以捕获宝石中的弃用警告之前(即在 Bundler.require(:default,Rails.env)是否已定义之前?((bundler)
在application.rb中)。
As @Eric Anderson says it should be placed after Rails loads (i.e. after require 'rails/all'
in application.rb) but before bundler runs to catch deprecation warning in gems (i.e. before Bundler.require(:default, Rails.env) if defined?(Bundler)
in application.rb).
您可以添加一个条件,例如 if ENV [ DEBUG]
或 if environment ==:test
将此保留在您的配置中。
You can add a condition, like if ENV["DEBUG"]
or if environment == :test
to leave this in your config.
这篇关于跟踪Rails测试中的弃用警告源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!