“version_requirements deprecated” warning in rails

March 1, 2010

in software, web

[NOTE: This post is getting an alarming number of hits... everyone be sure and note the update at the bottom]

Another minor annoyance with a quick fix:
If you’re getting this warning:

Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010.  Use #requirement

when running anything using rails (i believe this occurs in rails 2.3.4 or higher) with gems version 1.3.6, it seems like a fix will be released sometime soon.
However, if you’re not running edge rails and just want this warning to go away, you can just apply the patch, but be warned that I had to change the quoted “requirement” in gem_dependency.rb:

119
      r = Gem::Dependency.instance_methods.include?("requirement") ? super : version_requirements

to a symbol:

119
      r = Gem::Dependency.instance_methods.include?(:requirement) ? super : version_requirements

… not sure if that’s just a ruby 1.9 thing, didn’t feel like investigating any further. Silly warning is gone! Darn thing was cluttering up every script, test run, server start, rake task….

cheers!

UPDATE:

Seems I spoke too soon. And didn’t re-read the changelog before making this post — the commited patch is a little more reworked and *does* use the symbol. Good!

{ 6 comments… read them below or add one }

Lou March 23, 2010 at 12:51 pm

I didn’t know how to apply the committed patch, so in case others have the same problem:

curl http://github.com/rails/rails/commit/268c9040d5c3c7ed30f3923eee71a78eeece8a8a.diff | sudo patch -d /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/rails

Just remember to switch out the directory after -d with wherever gem_dependency.rb lives on your system (it’s in the warning message). It is probably bad practice to patch your system gems, but to get rid of this warning we can make an exception :)

Oh, and if something goes wrong, reverse the patch with:

curl http://github.com/rails/rails/commit/268c9040d5c3c7ed30f3923eee71a78eeece8a8a.diff | sudo patch -d /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/rails -R

matt March 23, 2010 at 1:12 pm

good tip, thanks! –

You are right that patching system gems isn’t the safest thing in the world to do — an update might overwrite what you’ve done, or you could accidentally break something you don’t mean to. In this case, it’s a rather trivial alteration, that shouldn’t have any nasty side affects. A safer alternative may be to localize your rails gem in your /vendor directory, and apply the patch there. That way you leave your system rails untouched…

Christopher Dwan March 25, 2010 at 3:22 pm

Yes. I just ignored this error for a few weeks and finally went looking for an answer and POOF! Gone.

That command from Lou worked for me just cut and paste to the command line. The only thing was that the patch was looking for gem_dependency_test.rb which my system apparently doesn’t have. I skipped patching that file and it appears to have worked fine.

Anooj Rajan April 21, 2010 at 4:23 pm

Thanks for the patch.. Worked like a charm…

Dan Tripp May 11, 2010 at 11:59 pm

THANK YOU! :)

I used Lou’s tip, with the added step of doing “sudo ping yahoo.com” first so that I could enter the sudo password… otherwise it sorta “hangs” (in the bad way).

Anurag June 25, 2010 at 7:23 am

@Dan, “sudo ls” – shorter way to let sudo remember you

Leave a Comment

Previous post:

Next post: