弃用警告:不推荐使用alias_method_chain

Ale*_*tko 15 rspec ruby-on-rails ruby-on-rails-5

我将项目升级到Rails 5.当我运行时,rspec我收到警告

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. 
From module, you can access the original method using super. 
(called from <top (required)> at /home/alex/projects/myproject/config/application.rb:13)
Run Code Online (Sandbox Code Playgroud)

application.rb中的失败行是:

Bundler.require(*Rails.groups)
Run Code Online (Sandbox Code Playgroud)

如何找出导致此弃用警告的原因以及如何消除错误?

And*_*eko 19

安装(除非已安装)确认并在终端中运行:

ack alias_method_chain /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.1/gems/
Run Code Online (Sandbox Code Playgroud)

它将指示使用的所有位置alias_method_chain(文件和代码行).

它有99%的几率用在你的宝石中.

请参阅我的答案,了解您可以采取的一系列措施.


Ban*_*eil 6

在 OSX 中,您可以使用:

grep -Ir alias_method_chain `bundle show rails`/..
Run Code Online (Sandbox Code Playgroud)

这将列出所有使用的宝石 alias_method_chain