I have inherited a huge Rails project with hundreds of warnings, due to other people's sloppy coding habits, none of which I can fix.
When I run an individual test suite, with ruby test/function/my_controller_test.rb
, I get a clean run with no warnings. But when I run rake test
, something deep in Rails's rake tasks turns on ruby -w
, activating Ruby's warning system. How do I deactivate that line? I will edit the source and erase the -w
if I must, but where is it?
The answer is not rake -q
- that turns off rake's own spew.
If rake is invoked with a “TEST=filename” command line option, then the list of test files will be overridden to include only the filename specified on the command line. This provides an easy way to run just one test.
But proper way to manage warnings is to fix them and updating the gems which fix them. Want to know more about Ruby 2.7? Subscribe to my mailing list. I am looking for remote work related to Ruby/Rails.
Even running rails server prints all of these warnings before showing actual output. Fortunately, we can silence these deprecation warnings easily. Along with introducing lot of deprecation warnings, Ruby 2.7 has also provided a way out by enhancing the command line W flag.
A rake task is just Ruby code. Therefore it can be unit tested just like any other Ruby code. (It can even be developed in a test-first way. Just saying.)
If you want to suppress this you can add this to your shell config if you're using a POSIX-type shell:
export RUBYOPT=-W0
Or you can prepend that to any command:
RUBYOPT=-W0 ruby ...
For other shells you'll need to set that environment variable somehow.
I'm sure this has long been resolved, but for any future folks finding this, there is a clean way to do with with in the rakefile. Just add t.warning = false
to your raketask config. So for example, a super generic one would be:
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['source_code/*_test.rb']
t.verbose = true
t.warning = false
end
Fixing the warnings is still the best solution, but if needed, here ya go :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With