2

In our current Ruby (ruby 2.4.2p131, installed by rbenv as 2.4.0-dev) (NOT Rails) project we use a number of gems that produce warnings. I appreciate warnings that are caused by our own code and want to see and remove them, but there is not much to be done about warnings from gems. Is there a way to show only our own warnings?

I searched for similar questions, but they either require Rails, or want to disable ALL warnings. Both doesn't meet our requirements.

I also tried the warning gem (https://rubygems.org/gems/warning/versions/0.10.0) but failed to produce any change with it.

EDIT Here is two of the warnings that I don't want to see:
aws-sdk-resources-2.9.8/lib/aws-sdk-resources/services/s3/object.rb:61: warning: method redefined; discarding old copy_from

aws-sdk-core-2.9.8/lib/aws-sdk-core/plugins/s3_accelerate.rb:75: warning: assigned but unused variable - ssl

grackkle
  • 776
  • 1
  • 9
  • 26
  • I'm not sure why you'd want to do this. Warnings from 3rd party libraries are equally valid -- you shouldn't just be ignoring them because it's "not your code". – Tom Lord Jun 01 '17 at 15:23
  • However, does this answer your question https://stackoverflow.com/a/5591812/1954610 ? (See the final paragraph.) – Tom Lord Jun 01 '17 at 15:26
  • 1
    @TomLord When a 3rd party gem didn't align a end to its corresponding if, I honestly don't care too much, since I don't have to work with the code myself. The gem itself is fully functional and I use the latest version. About the final paragraph of that answer: I doubt that it will help, since I don't have a environment.rb or application.rb. Both seem to be Rails specific. I can try to do something similar around a Gemfile, but I'm not sure that it will work. – grackkle Jun 02 '17 at 09:19
  • Hmm... I know this isn't *quite* what you've asked for, but have you considered just hiding those specific warnings with a "grep"? You could place something in `spec_helper.rb` to capture `$stdout` and filter it as desired. – Tom Lord Jun 02 '17 at 09:32
  • True, not quite what I wanted, but it gives me a direction. I'm usually calling rake to run the tests and then see the live output. I'm thinking about capturing stdout and stderr in the rake task and filter there... This way I can keep the simple call to rake (testing is set as default task) – grackkle Jun 02 '17 at 10:01
  • small addon: I also don't have a spec_helper.rb. We're using minitest. – grackkle Jun 02 '17 at 12:28
  • Best solution so far is `rake 2>&1 | grep -v ".rbenv"`. But I would prefer something in the rakefile. – grackkle Jun 02 '17 at 12:30
  • I agree with @bln-tom. I personally see the list of warnings on my personal code as a list of things for me to fix. I like the distinction with 3rd party ones. I can ignore them but some famous libraries have tons of them. This is line noise hell. – Mig Nov 21 '19 at 16:18

2 Answers2

0

See https://github.com/jeremyevans/ruby-warning/, which lets you ignore specific warnings by type and the file where they occurred (e.g. only in gems).

Jonathan Swartz
  • 1,913
  • 2
  • 17
  • 28
  • Generally, links to a tool or library [should be accompanied by usage notes, a specific explanation of how the linked resource is applicable to the problem, and some sample code](//meta.stackoverflow.com/a/251605/584192). If the tool or library is not free-to-use, please also mention this in your answer. – Samuel Liew Jan 15 '19 at 22:05
-1

Add $verbose = nil at the start of your test_helper file