Read more

Silence specific deprecation warnings in Rails 3+

Tobias Kraze
June 03, 2014Software engineer at makandra GmbH

Sometimes you're getting an ActiveSupport deprecation warning that you cannot or don't want to fix. In these cases, it might be okay to silence some specific warnings. Add this to your initializers, or require it in your tests:

silenced = [
  /Not considered a useful test/,
  /use: should(_not)? have_sent_email/,
] # list of warnings you want to silence

silenced_expr = Regexp.new(silenced.join('|'))

ActiveSupport::Deprecation.behavior = lambda do |msg, stack|
  unless msg =~ silenced_expr
    ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:stderr].call(msg, stack)
  end
end
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

This will only work with warnings that go through ActiveSupport and only in Rails 3.0 or higher.

Posted by Tobias Kraze to makandra dev (2014-06-03 10:49)