Ruby on Rails:将弃用警告视为错误还是以其他方式找到弃用的代码? [英] Ruby on Rails: Treat deprecation warnings as errors or otherwise find deprecated code?
问题描述
我最近从Rails 2升级到Rails 3,并且我试图清除所有我可能已弃用的代码。我这样做的方法只是浏览在开发机器上运行的网站副本,并凝视控制台的输出以获取警告。
I recently upgraded from Rails 2 to Rails 3, and I'm trying to root out all the code I might have that is deprecated. The way I'm doing this is just surfing around a copy of my site running on a development machine, and peering at the output from the console for warnings.
一种使Rails将弃用警告视为错误或以其他方式更有效地查找弃用代码的方法?
Is there a way to cause Rails to treat deprecation warnings as errors or otherwise find deprecated code more efficiently?
推荐答案
您可以自定义行为通过设置 ActiveSupport :: Deprecation.behavior
弃用呼叫。应将其设置为 Proc
,以接受消息和调用栈,例如您可以这样做:
You can customise the behaviour of deprecated calls by setting ActiveSupport::Deprecation.behavior
. This should be set to a Proc
that accepts a message and a callstack e.g. you could do:
ActiveSupport::Deprecation.behavior = Proc.new { |message, callstack|
raise message + "\n" + callstack.join("\n ")
}
如果您对应用程序进行了自动化测试,则在升级所使用的Rails版本时,这些功能将非常宝贵。
If you have automated tests for your app these are invaluable when upgrading the version of Rails being used.
这篇关于Ruby on Rails:将弃用警告视为错误还是以其他方式找到弃用的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!