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?

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Alex Nikolsky
  • 2,087
  • 6
  • 21
  • 36

4 Answers4

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.

Community
  • 1
  • 1
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
  • @AlexanderShmatko make sure to provide correct path to your current gems directory :) – Andrey Deineko Oct 21 '16 at 10:17
  • If anyone wants to install `ack` mentioned above through `CPAN`, here's a great tutorial for a newbie https://egoleo.wordpress.com/2008/05/19/how-to-install-perl-modules-through-cpan-on-ubuntu-hardy-server/ – Swaps Dec 08 '17 at 14:01
  • or use `ag` instead of `ack` - same thing, but faster – Tilo Mar 20 '18 at 05:46
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

BananaNeil
  • 10,322
  • 7
  • 46
  • 66
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"
}
Hirurg103
  • 4,783
  • 2
  • 34
  • 50
2

Solution for docker :

docker exec -it [CONTAINER_NAME] /bin/bash

apt-get install silversearcher-ag

ag alias_method_chain $GEM_HOME"/gems"

Community
  • 1
  • 1