首页 > 解决方案 > 如何在没有弃用警告的情况下运行 rspec

问题描述

但是,每当我尝试运行时,我都试图遵循“ RSpec 入门 - 第 1 部分”

rspec

我收到:

/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:29: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:30: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/2.5.0/specifications/raspell-1.3.gemspec:20.
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated

An error occurred while loading spec_helper.
Failure/Error: return gem_original_require(path)

LoadError:
  cannot load such file -- spec_helper
# /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
# /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration.rb:2103:in `load_file_handling_errors'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration.rb:1565:in `block in requires='
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration.rb:1565:in `each'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration.rb:1565:in `requires='
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration_options.rb:113:in `block in process_options_into'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration_options.rb:112:in `each'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration_options.rb:112:in `process_options_into'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/configuration_options.rb:22:in `configure'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/runner.rb:132:in `configure'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/runner.rb:99:in `setup'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/runner.rb:86:in `run'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/runner.rb:71:in `run'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/lib/rspec/core/runner.rb:45:in `invoke'
# /var/lib/gems/2.5.0/gems/rspec-core-3.9.2/exe/rspec:4:in `<top (required)>'
# /usr/local/bin/rspec:23:in `load'
# /usr/local/bin/rspec:23:in `<main>'
# 
#   Showing full backtrace because every line was filtered out.
#   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
#   RSpec::Configuration#backtrace_inclusion_patterns for more information.
No examples found.


Finished in 0.00004 seconds (files took 0.06007 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

我是 Rspec 的新手。我检查了ruby -v

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

然而,gem -v结果是:

/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:29: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:30: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/dnsruby-1.54.gemspec:17.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/erubis-2.7.0.gemspec:17.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/image_science-1.2.2.gemspec:20.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/net-http-persistent-2.9.4.gemspec:20.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/2.5.0/specifications/raspell-1.3.gemspec:20.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/snmp-1.2.0.gemspec:18.
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:29: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:30: warning: constant Gem::ConfigMap is deprecated
3.1.3

我尝试安装 Nokogiri 并修复Gem::ConfigMap已弃用的问题,但似乎没有任何效果。

我应该如何运行测试?

标签: ruby-on-railsruby

解决方案


一段时间以来,我在加载我的“calculator_spec.rb”测试时遇到了问题,无论是否使用“spec_helper”,您展示的本教程“RSpec 简介 - 第 1 部分”非常简单。如果您按照步骤操作,此问题不在 spec_helper 中,而在于您在文本编辑器中的编写方式。我使用 sublime,尽量不要给 Ctrl + C - V,键入代码,因为引号,空格可以在解释器之后以不同的方式解释。至于弃用的gem,您使用的是rspec 3.1版,您的帖子没有当前版本3.9那么旧,请不要在Gemfile中指定版本,因为它会自动安装最新版本。

建议:使用更新版本的 ruby​​。最好使用 RVM。按照提供的教程进行操作,无需复制和粘贴,现在不要做任何超出范围的操作。(没有安装spec_helper)。


推荐阅读