没有要加载的文件 -- rspec/matchers - rspec-rails、shoulda、黄瓜、工厂女孩、Rails2.3.10

发布于 2024-11-13 07:45:18 字数 4419 浏览 3 评论 0原文

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

不管怎样,我发现很难在互联网上找到展示如何在 Rails 2.3 环境中设置 rspec、cucumber、factory girls 和 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, 

,我从应该得到以下堆栈跟踪:

/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 而不是捆绑包。

I've inherited an old Rails2.3 app. It's very complex and has (shock, horror) no tests whatsoever. I'm used to rspec and cucumber so I thought I'd start working on getting specs and features defined for the eventual (long-away) upgrade to Rails 3. It's easier to upgrade if I know exactly what will fail.

Anyway, I found it very difficult to find resources on the internet that show how to set up rspec, cucumber, factory girl, and shoulda in a rails 2.3 environment. My bundle is as follows:

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

When I go to run

bundle exec rspec spec, 

I get the following stacktrace from 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

Googling for that error provides frighteningly few hits... I'm not sure what I've done wrong?

Removing rspec-core gives:

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 is not part of the bundle. Add it to Gemfile. (Gem::LoadError)

contents of 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)

I wonder if this is conflicting with other rspec's I have installed (I've a Rails3 app installed, also with bundler/rvm)... Not sure why rspec is being run out of opt/local/bin and not the bundle, though..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨的味道风的声音 2024-11-20 07:45:18

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

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

别名可能允许 rspec 1.3.2 也响应“rspec”命令,但对我来说情况并非如此。使用“spec”对于避免调用 rspec-core 和其他 2.x 模块是 100% 可靠的。

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

I ran into this same problem. After hunting down all binary rspec commands (several locations), I belatedly realized that the 1.3.2 branch of RSPEC titles its binary "spec" and not "rspec".

So the correct commands was always "bundle exec spec spec/models/..." Putting "rspec" meant that bundler failed to find it in my current rvm/gemset and went searching through my entire path, eventually coming up with an /opt/local/bin copy that belonged to an rspec2.x install.

It is possible that an alias allows rspec 1.3.2 to also respond to the "rspec" command, but that was not the case for me. Using "spec" was 100% reliable for avoiding that call for rspec-core and other 2.x modules.

Thanks for the question and all the research above. Charles

当爱已成负担 2024-11-20 07:45:18

看起来 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        

It looks like rspec-core, which is from a version of rspec that only supports Rails 3, may be the problem. Try uninstalling that and removing it from your Gemfile.

For comparison, here's a section from our Gemfile that works fine for 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        
云淡月浅 2024-11-20 07:45:18

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

A bundle update rspec-rails fixed this issue for me on rails 3.1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文