DEPRECATION WARNING: alias_method_chain is deprecated
Asked Answered
L

4

17

I upgraded the project to Rails 5. When I run rspec I get a warning

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)

The failing line in application.rb is:

Bundler.require(*Rails.groups)

How do I find out what is causing this deprecation warning and how to get rid of the error?

Lockwood answered 21/10, 2016 at 9:58 Comment(0)
T
24

Install (unless already installed) ack and run in the terminal:

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

It will indicate all places where alias_method_chain is used (files and code lines).

99% chance it is used in some of your gems.

See my answer for a list of things you can do about it.

Tuft answered 21/10, 2016 at 10:0 Comment(3)
@AlexanderShmatko make sure to provide correct path to your current gems directory :)Tuft
If anyone wants to install ack mentioned above through CPAN, here's a great tutorial for a newbie egoleo.wordpress.com/2008/05/19/…Bistoury
or use ag instead of ack - same thing, but fasterGerlac
L
7

In OSX, you can use:

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

And that will list all of the gems that use alias_method_chain

Lima answered 22/1, 2018 at 8:57 Comment(0)
M
3

If the Gemfile is too large I would recommend to use the_silver_searcher to search for deprecated alias_method_chain because it is faster

ag alias_method_chain /path/to/gemset

I have gepgems bash helper function to not type /path/to/gemset every time

grepgems alias_method_chain

To use it add the following function to your .bash_profile (or somewhere else in the dotfiles you like)

function grepgems() {
  ag $1 $GEM_HOME"/gems"
}
Marylnmarylou answered 11/5, 2017 at 16:11 Comment(0)
D
2

Solution for docker :

docker exec -it [CONTAINER_NAME] /bin/bash

apt-get install silversearcher-ag

ag alias_method_chain $GEM_HOME"/gems"

Druid answered 22/7, 2018 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.