I'm looking for a way to suppress Ruby warnings when I run my specs.
spec spec/models/account_spec.rb
I receive warnings such as:
DEPRECATION WARNING: ActiveSupport::Dependencies.load_paths is deprecated, ...
warning: already initialized constant SOME_CONSTANT_NAME
Removing the ActiveSupport
warning is quite easy with ActiveSupport::Deprecation.silenced = true
.
How do I prevent the already initialized constant warnings as part of my spec
command? Or through creating another spec
file that can suppress such warnings. Keep in mind that these warnings are from gem files, therefore I cannot go into those files and surround them with Kernel.silence_warnings
.
Note:
I understand that suppressing warnings are bad. However, when I run a single spec
from within vim
it would be nice if the warnings didn't clutter my screen.
Related with this post, you can manage deprecation warnings according to th environment in which you are working, as said in rails guides:
So just change in
config/environments/test.rb
the value :stderr for :logAnd with this change, the deprecation warnings will now be printed to the
log/test.log
instead of the console output.Actually, perhaps you shouldn't ignore your warnings, but test them, to make sure they are fired where they're supposed to be.
It's not the easiest to use, but it looks like this:
I found it here, and tested it for my use case, and it works (and the warnings disappear from the console, of course)
The only solution that worked for me is to add
$VERBOSE = nil
on top of my config/environments/test.rb fileI'm with faker warning problems
faker-1.9.6/lib/faker/default/number.rb:34
. Use it local because it hides all other warnings.If you have this in your
.rspec
file, removefrom your
.rspec
file in your project root.You can also use the "RUBYOPT" environment variable to pass -W0 to rspec:
This allows you to run multiple specs by passing in a directory
The syntax for
RUBYOPT
isTested in ruby 2.1.x and 2.14.x