Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trace source of deprecation warnings in rails tests

Tags:

When running my functional tests, I'm getting the following warning in one of the test cases but I can't pinpoint where it's coming from:

gems/actionpack-2.3.8/lib/action_controller/record_identifier.rb:76: warning: Object#id will be deprecated; use Object#object_id

Unfortunately that's the only line of the backtrace that's shown, even if I run it with rake test --trace, and there is no more information in log/test.log.

How can I get the full backtrace for this warning or otherwise figure out which line in my code is causing it?

like image 566
Andrew Vit Avatar asked Sep 08 '10 21:09

Andrew Vit


People also ask

What is deprecation warnings?

Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.

How do you get rid of warnings in Ruby?

Then the only way so remove them all is to: Add $VERBOSE = nil to config/environments/test. rb. Run guard with: RUBYOPT='-W0' bundle exec guard.

Is Ruby deprecated?

On 26 March 2019, the deprecation period for Ruby Sass will end and it will no longer be maintained.


1 Answers

To solve this you could enable the full debugging information. (see the help)

ActiveSupport::Deprecation.debug = true 

As @Eric Anderson says it should be placed after Rails loads (i.e. after require 'rails/all' in application.rb) but before bundler runs to catch deprecation warning in gems (i.e. before Bundler.require(:default, Rails.env) if defined?(Bundler) in application.rb).

You can add a condition, like if ENV["DEBUG"] or if environment == :test to leave this in your config.

like image 171
eloyesp Avatar answered Sep 26 '22 04:09

eloyesp