【问题标题】:no such file to load -- rspec/matchers - rspec-rails, shoulda, cucumber, factory girl, Rails2.3.10没有要加载的文件 -- rspec/matchers - rspec-rails, shoulda, cucumber, factory girl, Rails2.3.10
【发布时间】:2011-06-02 13:58:57
【问题描述】:

我继承了一个旧的 Rails2.3 应用程序。它非常复杂,并且(震惊,恐怖)没有任何测试。我已经习惯了 rspec 和 cucumber,所以我想我会开始着手为 Rails 3 的最终(长期)升级定义规范和特性。如果我确切知道什么会失败,升级会更容易。

无论如何,我发现在 Internet 上很难找到展示如何在 rails 2.3 环境中设置 rspec、cucumber、factory girl 和 shoulda 的资源。我的包如下:

source "http://rubygems.org"

# Production gems
gem "rails",    "2.3.10"
gem "nokogiri", "1.4.4"
gem "mysql",    "~> 2.8.1"

group :development do
  # bundler requires these gems in development
  gem 'rspec',          '1.3.2'
  gem 'rspec-core',     '2.5.2'
  gem 'rspec-rails',    '1.3.4'
end

group :test do
  # bundler requires these gems while running tests
  gem 'cucumber-rails', '0.4.1'
  gem 'factory_girl'
  gem 'shoulda',        '2.11.3'
  gem 'shoulda-matchers'
end

当我去跑步时

bundle exec rspec spec, 

我从 shoulda 得到以下堆栈跟踪:

/Users/sys/src/proj/rails/ruby/1.8/gems/shoulda-2.11.3/lib/shoulda/integrations/rspec2.rb:8: no such file to load -- rspec/matchers (MissingSourceFile)
    from /Users/sys/src/proj/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in `require'
    from /Users/sys/src/proj/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in `require'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/shoulda-2.11.3/lib/shoulda.rb:4
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler.rb:120:in `require'
    from /Users/sys/src/proj/config/boot.rb:119:in `load_gems'
    from /Users/sys/src/proj/config/../vendor/rails/railties/lib/initializer.rb:164:in `process'
    from /Users/sys/src/proj/config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
    from /Users/sys/src/proj/config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
    from /Users/sys/src/proj/config/environment.rb:12
    from /Users/sys/src/proj/spec/spec_helper.rb:4:in `require'
    from /Users/sys/src/proj/spec/spec_helper.rb:4
    from /Users/sys/src/proj/spec/models/announcement_spec.rb:1:in `require'
    from /Users/sys/src/proj/spec/models/announcement_spec.rb:1
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `map'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:46:in `run'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:10:in `autorun'
    from /Users/sys/src/proj/rails/ruby/1.8/bin/rspec:19

谷歌搜索该错误提供的点击率非常低...我不确定我做错了什么?

删除 rspec-core 给出:

bundle exec rspec spec/models/announcement_spec.rb /Users/sys/.rvm/gems/ree-1.8.7-2011.03@proj/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:143:in `gem': rspec-core 不属于捆绑。将其添加到 Gemfile。 (Gem::LoadError)

opt/local/bin/rspec 的内容

cat /opt/local/bin/rspec 
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'rspec-core' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'rspec-core', version
load Gem.bin_path('rspec-core', 'rspec', version)

我想知道这是否与我安装的其他 rspec 冲突(我安装了 Rails3 应用程序,也安装了 bundler/rvm)...不知道为什么 rspec 用完 opt/local/bin 而不是捆绑,不过..

【问题讨论】:

    标签: ruby-on-rails rspec cucumber factory-bot shoulda


    【解决方案1】:

    我遇到了同样的问题。在搜索了所有二进制 rspec 命令(几个位置)之后,我才意识到 RSPEC 的 1.3.2 分支将其命名为二进制“spec”而不是“rspec”。

    所以正确的命令总是“bundle exec spec spec/models/...” 输入“rspec”意味着捆绑器无法在我当前的 rvm/gemset 中找到它并搜索我的整个路径,最终想出了属于 rspec2.x 安装的 /opt/local/bin 副本。

    别名可能允许 rspec 1.3.2 也响应“rspec”命令,但对我来说不是这样。使用“spec”可以 100% 可靠地避免调用 rspec-core 和其他 2.x 模块。

    感谢您提出问题和上述所有研究。查尔斯

    【讨论】:

      【解决方案2】:

      看起来 rspec-core 可能是问题所在,它来自仅支持 Rails 3 的 rspec 版本。尝试卸载它并将其从您的 Gemfile 中删除。

      为了比较,下面是我们的 Gemfile 中适用于 Rails 2.3 的部分:

      group :development, :local, :test do                                             
        gem "rspec",              "= 1.3.1"                                            
        gem "rspec-rails",        "= 1.3.3"                                            
        gem "factory_girl",       "= 1.3.3"                                            
        gem "webrat",             "= 0.7.3"                                            
        gem "shoulda",            "= 2.11.3"                                           
      end        
      

      【讨论】:

      • 如果我删除 rspec-core,我会得到:/Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:143:in `gem': rspec-core 不是捆绑包的一部分。将其添加到 Gemfile。 (Gem::LoadError) 来自 /Users/sys/src/proj/rails/ruby/1.8/bin/rspec:18
      • 我会尝试卸载所有 rspec gems,将上述 2 个 gems 放入您的 Gemfile 中,然后运行 ​​bundle install。
      • 仍然会导致问题。但是,现在它抱怨该文件来自 /opt/local/bin/rspec:18 ...您的该脚本的文件内容是什么?
      • 为确保您运行的是正确的可执行文件,请使用bundle exec,例如bundle exec rake spec.
      • 你知道,如果有一个网站列出了不同 gem 环境中给定版本的 rails 的所有依赖项,这真的很有帮助。有很多这样的问题,但很少有明确的答案(很多答案都是片面的,并且遗漏了各种依赖项)。不幸的是,bundler 不能总是为您选择正确的版本!
      【解决方案3】:

      bundle update rspec-rails 在 rails 3.1 上为我解决了这个问题。

      【讨论】:

        猜你喜欢
        • 2012-06-12
        • 2015-01-14
        • 1970-01-01
        • 2016-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-30
        • 2014-01-12
        相关资源
        最近更新 更多