Posted over 8 years ago. Visible to the public.

Silence specific deprecation warnings in Rails 3+

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:

Copy
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

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

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Avatar
Tobias Kraze
Last edit:
over 7 years ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Tobias Kraze to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more