And*_*Vit 22 warnings unit-testing ruby-on-rails deprecated
在运行我的功能测试时,我在其中一个测试用例中收到以下警告,但我无法确定它来自何处:
gems/actionpack-2.3.8/lib/action_controller/record_identifier.rb:76: warning: Object#id will be deprecated; use Object#object_id
不幸的是,这是显示的回溯的唯一一行,即使我运行它rake test --trace,并且没有更多的信息log/test.log.
如何获取此警告的完整回溯或以其他方式确定我的代码中的哪一行导致它?
elo*_*esp 40
要解决此问题,您可以启用完整的调试信息.(见帮助)
ActiveSupport::Deprecation.debug = true
Run Code Online (Sandbox Code Playgroud)
正如@Eric Anderson所说,它应该在Rails加载之后(即require 'rails/all'在application.rb之后)放置,但是在bundle运行之前捕获gem中的弃用警告(即Bundler.require(:default, Rails.env) if defined?(Bundler)在application.rb 之前).
您可以添加条件,例如if ENV["DEBUG"]或if environment == :test将其保留在配置中.
有同样的问题.一个gem导致了弃用警告,但我不知道哪个gem,因为Rail的消息只显示了我的代码中callstack的最后一位.添加以下内容:
module ActiveSupport::Deprecation
class << self
def deprecation_message_with_debugger(callstack, message = nil)
debugger
deprecation_message_without_debugger callstack, message
end
alias_method_chain :deprecation_message, :debugger
end
end
Run Code Online (Sandbox Code Playgroud)
在Rails加载之后(即require 'rails/all'在application.rb之后)但在Bunder运行之前放置这个以捕获gem中的弃用警告(即Bundler.require(:default, Rails.env) if defined?(Bundler)在application.rb 之前).
现在遇到弃用警告时,您将被丢弃在调试器中.您可以将其留在(并用a环绕if Rails.env.test?)或在找到问题后将其删除.