Search code examples
ruby-on-railsrubyrspecrspec-rails

How to Suppress Warnings in RSpec while running Ruby 2.7.0


After installing Ruby 2.7.0 running specs has become a nightmare of warnings such as this one:

/Users/user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/capybara-3.30.0/lib/capybara/node/matchers.rb:835: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/capybara-3.30.0/lib/capybara/node/matchers.rb:861: warning: The called method `_set_query_session_options' is defined here

Since these warnings are popping out of gems, they really aren't helping and making RSpec output a total mess.

I have tried adding this line to the spec_helper.rb

config.warnings = false

And this line to config/environments/test.rb

config.active_support.deprecation = :log

But yet, the warnings still pop up by the hundreds. Is there anything I can do to be rid of them?

Running Ruby on Rails 6.0.2.1 and Ruby 2.7.0

NOTE It has been suggested that the answer to this question already exists in Suppress Ruby warnings when running specs This looks like a similar question, but the solution provided has no effect. I see all of the warnings.


Solution

  • 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