在Rails 4上使用RSpec保护,发出很多警告

时间:2014-06-02 21:07:55

标签: ruby-on-rails ruby ruby-on-rails-4 rspec

我想知道如何在运行简单测试时关闭所有这些警告:

[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

我正在运行Rails 4.1.1,Ruby 2.1.2p95和...

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

我已经尝试过守卫:

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

而不是:

guard :rspec, cmd:"spring rspec" do

但它没有做任何事情。

这些警告非常烦人,而且我很确定我没有引起它们。救命啊!

2 个答案:

答案 0 :(得分:138)

rspec生成器rails generate rspec:install现在默认将--warnings选项放在.rspec文件中。删除该行,警告就会消失。

答案 1 :(得分:12)

您可以在测试环境中将警告设置为false,以强制Rspec禁用警告消息。

#spec / spec_helper.rb

config.warnings = false