我想知道如何在运行简单的测试时关闭所有这些警告:
[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: …Run Code Online (Sandbox Code Playgroud) 是否有可能使用RSpec测试Ruby的警告?
像这样:
class MyClass
def initialize
warn "Something is wrong"
end
end
it "should warn" do
MyClass.new.should warn("Something is wrong")
end
Run Code Online (Sandbox Code Playgroud) 我在我的Rails 5.0.0.1应用程序中使用unscoped_associations gem.
我收到这个弃用警告:
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/rhl/myapp/config/application.rb:8)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/rhl/myapp/config/application.rb:8)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/rhl/myapp/config/application.rb:8) …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置我的 Rails 3.2 应用程序的 cloud9 ( https://c9.io ) 测试安装,以便新开发人员可以快速启动并运行它以提交更改和运行测试。我所有的测试都通过了,但它们与许多与不同 gem 相关的警告混合在一起:
加载套件 /usr/local/rvm/gems/ruby-2.1.2/gems/rake-11.1.1/lib/rake/rake_test_loader 开始 ...... 在 0.22973343 秒内完成。 ------ 6 次测试、10 次断言、0 次失败、0 次错误、0 次待处理、0 次遗漏、0 次通知 0% 通过 ------ 26.12 次测试/秒,43.53 次断言/秒 加载套件 /usr/local/rvm/gems/ruby-2.1.2/gems/rake-11.1.1/lib/rake/rake_test_loader 开始 ……………………………………………………………………………………………………………………………………………………………………………… 在 4.18306875 秒内完成。 ------ 44 次测试、77 次断言、0 次失败、0 次错误、0 次未决、0 次遗漏、0 次通知 /usr/local/rvm/gems/ruby-2.1.2/gems/composite_primary_keys-5.0.14/lib/composite_primary_keys/relation.rb:26: 警告:destroy 的先前定义在这里 /usr/local/rvm/gems/ruby-2.1.2/gems/composite_primary_keys-5.0.14/lib/composite_primary_keys/relation.rb:10:警告:方法重新定义;丢弃旧的删除 /usr/local/rvm/gems/ruby-2.1.2/gems/composite_primary_keys-5.0.14/lib/composite_primary_keys/relation.rb:10: 警告:先前的删除定义在这里 /usr/local/rvm/gems/ruby-2.1.2/gems/composite_primary_keys-5.0.14/lib/composite_primary_keys/relation.rb:26:警告:方法重新定义;丢弃旧的销毁
...它继续并为许多其他宝石生成警告。
在我自己的 Ubuntu/Debian 机器上,我没有看到这些警告,而且它们让我很难看到现在散布在其他几十行警告中的测试结果。
有没有办法抑制警告或配置我的测试,以便它们不会触发这种级别的冗长?
安装 Ruby 2.7.0 后,运行规范已成为诸如此类警告的噩梦:
/Users/user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/capybara-3.30.0/lib/capybara/node/matchers.rb:835: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/capybara-3.30.0/lib/capybara/node/matchers.rb:861: warning: The called method `_set_query_session_options' is defined here
Run Code Online (Sandbox Code Playgroud)
由于这些警告是从 gem 中弹出的,它们确实没有帮助,并且使 RSpec 输出变得一团糟。
我曾尝试将此行添加到 spec_helper.rb
config.warnings = false
Run Code Online (Sandbox Code Playgroud)
这行到 config/environments/test.rb
config.active_support.deprecation = :log
Run Code Online (Sandbox Code Playgroud)
但是,仍然有数百个警告弹出。我能做些什么来摆脱它们吗?
运行 Ruby on Rails 6.0.2.1 和 Ruby 2.7.0
注意 有人建议在运行规范时抑制 Ruby 警告中已经存在这个问题的答案这看起来像一个类似的问题,但提供的解决方案没有效果。我看到了所有的警告。