Suppress Ruby warnings when running specs

前端 未结 10 2181
野趣味
野趣味 2020-11-27 14:46

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:

相关标签:
10条回答
  • 2020-11-27 15:34

    Putting Warning[:deprecated] = false after require "rails/all" in config/application.rb works very well to suppress those warnings everywhere. You can do

    Warning[:deprecated] = false if Rails.env.test?
    

    for your particular case, or better yet - put it in config/environments/test.rb, but I'm not sure how well it is going to work since I belive some stuff is loaded before that.

    0 讨论(0)
  • 2020-11-27 15:36

    You can also use the "RUBYOPT" environment variable to pass -W0 to rspec:

    RUBYOPT=W0 rspec spec/models/event_spec.rb
    

    This allows you to run multiple specs by passing in a directory

    RUBYOPT=W0 rspec spec/models
    
    0 讨论(0)
  • 2020-11-27 15:40

    The only solution that worked for me is to add $VERBOSE = nil on top of my config/environments/test.rb file

      Rails.application.configure do
       $VERBOSE = nil
    

    I'm with faker warning problems faker-1.9.6/lib/faker/default/number.rb:34. Use it local because it hides all other warnings.

    0 讨论(0)
  • 2020-11-27 15:43

    rspec has a tag option you can use -- I simply used /dev/null.

    rspec spec --deprecation-out /dev/null
    
    0 讨论(0)
提交回复
热议问题