Bundler:无法加载命令:rspec。

3

我是Rails的新手,我想在Mac上运行Rspec测试。

当我输入以下命令时:

bundle exec rspec spec/00_hello_spec.rb 

我得到了以下的回应:
bundler: failed to load command: rspec (/Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/bin/rspec)
LoadError: cannot load such file -- spec_helper
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `require'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `block in requires='
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `each'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `requires='
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:110:in `block in process_options_into'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:109:in `each'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:109:in `process_options_into'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:22:in `configure'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:96:in `setup'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/bin/rspec:22:in `load'
  /Users/OumouKaba/Downloads/test-first-ruby-master/vendor/bundle/ruby/2.4.0/bin/rspec:22:in `<top (required)>'

请协助提出任何建议或澄清此问题。另外,我已从根目录向上在文件系统的各个级别进行了此操作。非常感谢任何澄清以帮助我摆脱我的困境。


2
你运行了 rails generate rspec:install 吗? - Sebastián Palma
文件 spec/spec_helper.rb 存在吗?通常情况下,该文件会自动生成,但是您也可以手动添加它。 - Tom Lord
1
你的文件 spec/00_hello_spec.rb 的第一行很可能是 require "spec_helper",但是该文件不存在。这就是错误信息告诉你的内容。 - Tom Lord
3
我已经让它能够运行了。是哪个命令实现了这个功能? - Andrew Farrell
4
这种评论——“哦,没关系,我搞定了”——对那些在搜索错误信息后发现这个问题的其他人来说,是极其没有帮助的。 - pjmorse
显示剩余2条评论
1个回答

0

如果将来有人遇到此问题,请尝试查看是否安装了多个不同版本的rspec宝石,例如:

gem list | grep rspec

如果您这样做,请删除与您在Gemfile.lock中不匹配的宝石版本,如下所示:
gem uninstall <gem_name> <gem_version>

按照这些步骤后,我成功地运行了rspec spec


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接