61

I'm wondering how I can turn off all these warnings when running a simple test:

[1] guard(main)> 
16:59:46 - INFO - Run all
16:59:46 - INFO - Running all specs
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:124: warning: instance variable @example not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:124: warning: instance variable @example not initialized
.*

Pending:
  HomeHelper add some examples to (or delete) /Users/esjd/ruby/rails/ts3/spec/helpers/home_helper_spec.rb
    # Not yet implemented
    # ./spec/helpers/home_helper_spec.rb:14

Finished in 0.03601 seconds (files took 7 minutes 48 seconds to load)
2 examples, 0 failures, 1 pending
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized

/Users/esjd/.rvm/gems/ruby-2.1.2/gems/guard-2.6.1/lib/guard/interactor.rb:64: warning: instance variable @enabled not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/guard-2.6.1/lib/guard/interactor.rb:64: warning: instance variable @enabled not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/guard-2.6.1/lib/guard/interactor.rb:64: warning: instance variable @enabled not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/guard-2.6.1/lib/guard/interactor.rb:64: warning: instance variable @enabled not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized

I'm running Rails 4.1.1, Ruby 2.1.2p95, and...

guard (2.6.1)
rspec (3.0.0)
guard-rspec (4.2.9)

I've tried running guard with:

guard :rspec, cmd:"ruby -W0 bin/rspec" do

instead of:

guard :rspec, cmd:"spring rspec" do

But it didn't do anything.

These warnings are super annoying, and I'm pretty sure I'm not causing them. Help!

foobar
  • 10,854
  • 18
  • 58
  • 66

2 Answers2

139

The rspec generator rails generate rspec:install now puts the --warnings option in the .rspec file by default. Remove that line, and the warnings will go away.

Edward Anderson
  • 13,591
  • 4
  • 52
  • 48
  • 10
    That will remove *all* warnings right? What if you only want to remove warnings from gems? I'd like to see warnings from my own code. – Dennis Jun 11 '14 at 19:28
  • 3
    The --warnings option turns on or off warnings at the ruby level, and removing the option essentially keeps the default ruby and rails behavior. The answer to this question is not straightforward and deserves to be asked as a separate StackOverflow question. – Edward Anderson Jun 11 '14 at 23:17
  • e.g. see: http://stackoverflow.com/questions/5591509/suppress-ruby-warnings-when-running-specs – kkurian Jul 18 '14 at 04:36
13

You can set the warnings to false in the your test environment to force Rspec to disable the warnings messages.

# spec/spec_helper.rb

config.warnings = false

Icaro Seara
  • 139
  • 1
  • 2