Suppress Ruby Warnings When Running Specs

Suppress Ruby warnings when running specs

If you run your specs directly with the ruby command instead of the spec wrapper, you can use the -W command line option to silence warnings:

$ ruby --help
[...]
-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)

So in your case:

$ ruby -W0 -Ispec spec/models/event_spec.rb

should not show you any warnings.

Alternatively, you could set $VERBOSE=nil before your gems are loaded, ie at the top of your environment.rb (or application.rb if you're on Rails 3). Note that this disables all warnings all the time.

Or, since you are using Rails, you should be able to use Kernel.silence_warnings around the Bundler.require block if you're using Bundler:

Kernel.silence_warnings do
Bundler.require(:default, Rails.env) if defined?(Bundler)
end

More selectively, set $VERBOSE only for loading specific gems:

config.gem 'wellbehaving_gem'
original_verbosity = $VERBOSE
$VERBOSE = nil
config.gem 'noisy_gem_a'
$VERBOSE = original_verbosity

How to Suppress Warnings in RSpec while running Ruby 2.7.0

These warnings/deprecations are directly from the ruby 2.7, you cannot silence them by rails or rspec configuration.

Ruby 2.7 is trying to warn you about backward incompatibilities that will arrive in ruby 3.0. See the release notes. Main source of deprecations is the Separation of positional and keyword arguments part.

Rails and other libraries and gems are not prepared for this change yet, so ruby is showing you tons of warnings.

I would wait with upgrade until gems resolve these warnings in the future, but you can also suppress these warnings according to following article https://prathamesh.tech/2019/12/26/managing-warnings-emitted-by-ruby-2-7/

RUBYOPT='-W:no-deprecated -W:no-experimental' rails c

How to suppress deprecation warnings?

The warning is generated by the parser before the code is evaluated. That includes your Warning.ignore code, so the config isn't ready when the warning occurs.

You can move that code into a separate file:

# warn.rb
require 'warning'
Warning.ignore(/deprecated/)

and load it via -r:

$ ruby -r./warn.rb -e '0 if /a/.../b/'

How to Stop RSpec Warning Messages

If you have /.rspec file remove --warning option from it.

How can I figure out where a log message came from (and disable it)?

It's a Kernel.warn call in redis-namespace.

You can disable warnings in Ruby with the -W0 command line option.

More info on disabling warnings here:

Suppress Ruby warnings when running specs

Rspec: How to suppress warnings and notices when running tests?

Did you set: config.use_transactional_examples = true to false and see if that breaks anything?

Silence deprecation warning generated from of a gem

ActiveSupport::Deprecation.silenced = true

Exclude external gem warnings when running rake test in Rails

There are a number of options for different environments here: Suppress Ruby warnings when running specs

I used RUBYOPT=W0 rake test and this worked on a (crouton, ARM) Ubuntu 14 system with RVM.



Related Topics



Leave a reply



Submit