弃用警告:不推荐使用alias_method_chain

时间:2016-10-21 09:58:43

标签: ruby-on-rails rspec 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)

application.rb中的失败行是:

Bundler.require(*Rails.groups)

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

4 个答案:

答案 0 :(得分:17)

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

ack alias_method_chain /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.1/gems/

它将指示使用alias_method_chain的所有地方(文件和代码行)。

99%的几率用于你的宝石。

请参阅my answer,了解您可以采取的相关事项清单。

答案 1 :(得分:3)

在OSX中,您可以使用:

grep -Ir alias_method_chain `bundle show rails`/..

这将列出使用alias_method_chain

的所有宝石

答案 2 :(得分:1)

如果Gemfile太大,我建议使用the_silver_searcher搜索已弃用的alias_method_chain,因为它更快

ag alias_method_chain /path/to/gemset

我有gepgems bash帮助函数,每次都不输入/ path / to / gemset

grepgems alias_method_chain

要使用它,请将以下函数添加到.bash_profile(或您喜欢的dotfiles中的其他位置)

function grepgems() {
  ag $1 $GEM_HOME"/gems"
}

答案 3 :(得分:0)

泊坞窗解决方案:

  

docker exec -it [CONTAINER_NAME] / bin / bash

     

apt-get install silversearcher-ag

     

ag alias_method_chain $ GEM_HOME“ / gems”