【问题标题】:bundler: failed to load command: rspecbundler:加载失败命令:rspec
【发布时间】:2017-06-13 15:48:15
【问题描述】:

我是 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)>'

请提供有关此问题的任何建议或说明。补充一点,我已经在文件系统的各个级别从根向上完成了此操作。我非常感谢任何帮助我摆脱困境的澄清。

【问题讨论】:

  • 你跑rails generate rspec:install了吗?
  • 文件spec/spec_helper.rb是否存在?该文件通常是自动生成的,但如果您可以轻松地手动添加它。
  • 文件spec/00_hello_spec.rb 的第一行可能是require "spec_helper",并且该文件不存在。这就是错误消息告诉您的内容。
  • > 我能够让它工作 完成此操作的命令是什么?
  • 这种评论——“哦,没关系,我想通了”——对于其他在搜索错误消息后发现这个问题的人来说毫无帮助。

标签: ruby rspec


【解决方案1】:

如果以后有人遇到此问题,请尝试查看您是否安装了多个版本的不同 rspec gem,如下所示:

gem list | grep rspec

如果您这样做了,请删除与您的 Gemfile.lock 中的内容不匹配的 gem 版本,如下所示:

gem uninstall <gem_name> <gem_version>

按照这些步骤我能够成功运行rspec spec

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-05
    • 2021-06-30
    • 2023-04-09
    • 1970-01-01
    • 2022-08-17
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多