微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 没有这样的文件加载 – rspec / matchers – rspec-rails,shoulda,cucumber,factory girl,Rails2.3.10

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

无论如何,我发现很难在互联网上找到如何在rails 2.3环境中设置rspec,黄瓜,工厂女孩和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获得以下stacktrace:

/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. (宝石:: 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而不是捆绑包,尽管..

解决方法

我遇到了同样的问题.在查找所有二进制rspec命令(几个位置)之后,我姗姗来迟地意识到RSPEC的1.3.2分支标题为二进制“spec”而不是“rspec”.

因此,正确的命令始终是“捆绑exec规范/模型/ …”放置“rspec”意味着捆绑器无法在我当前的rvm / gemset中找到它并在我的整个路径中搜索,最终提出了/ opt属于rspec2.x安装的/ local / bin副本.

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

感谢上述问题和所有研究.查尔斯

原文地址:https://www.jb51.cc/ruby/270797.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐