rspec -w is not the same as ruby -w and does not show deprecation warnings
Created by: eregon
Subject of the issue
rspec -w
should show all warnings, notably deprecation warnings, so they are easily noticed when running tests/specs.
As background, Ruby 2.7.2+ does not show deprecation warnings by default, but ruby -w
does.
Part of the rationale for that was hoping that test frameworks would enable warnings by default, so deprecation warnings are still noticed when testing, while running an existing application would not show warnings from gems which cannot be addressed in the application.
This issue likely comes from setting $VERBOSE
to true does not enable deprecation warnings:
$ ruby -w -e 'def foo(**kwargs); end; foo({a:1})'
-e:1: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
-e:1: warning: The called method `foo' is defined here
$ ruby -e '$VERBOSE=true; def foo(**kwargs); end; foo({a:1})'
no warning
so deprecation warnings need to be enabled explicitly for rspec -w
with Warning[:deprecated] = true
.
MSpec does something related: https://github.com/ruby/mspec/blob/92c27b8aa6d2727ca0f630052a4f291587beaf33/lib/mspec/utils/warnings.rb#L3-L7
This issue makes it difficult to notice e.g. keyword arguments warnings in gems, because bundle exec rspec -w
does not show them.
Your environment
- Ruby version: 2.7.2
- rspec-core version: 3.10.0
Steps to reproduce
# some_spec.rb
def foo(**kwargs)
kwargs
end
RSpec.describe 'Test' do
it "should warn about keyword arguments with 'rspec -w'" do
expect(foo({a: 1})).to eq({a: 1})
end
end
No warnings without -w
:
$ rspec some_spec.rb
.
Finished in 0.00157 seconds (files took 0.05947 seconds to load)
1 example, 0 failures
RUBYOPT=-w
works and show the warning as expected:
$ RUBYOPT=-w rspec some_spec.rb
/home/eregon/tmp/some_spec.rb:7: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/eregon/tmp/some_spec.rb:1: warning: The called method `foo' is defined here
.
Finished in 0.00159 seconds (files took 0.06112 seconds to load)
1 example, 0 failures
rspec -w
does not show the deprecation warnings, which is this issue:
$ rspec -w some_spec.rb
.
Finished in 0.00158 seconds (files took 0.06062 seconds to load)
1 example, 0 failures