2011-06-02 65 views
8

我已經繼承了舊的Rails2.3應用程序。這非常複雜,並且(震驚,恐怖)沒有任何測試。我習慣了rspec和黃瓜,所以我想我會開始着手獲取爲最終(長期)升級到Rails 3而定義的規範和功能。如果我確切地知道哪些會失敗,那麼升級會更容易。沒有這樣的文件加載 - rspec/matchers - rspec-rails,shoulda,cucumber,factory girl,Rails2.3.10

無論如何,我發現很難找到互聯網上的資源,顯示如何在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, 

我從早該得到以下堆棧跟蹤:

/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的核心得出:

束的exec rspec的規格/型號/ announcement_spec.rb /Users/sys/.rvm/gems/[email protected]/gems/bundler-1.0 .14/lib/bundler/ruby​​gems_integration.rb:143:在`gem'中:rspec-core不是捆綁的一部分。將它添加到Gemfile。 (寶石:: LoadError)選擇/ 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中的應用程序,也有捆綁/ rvm)...不知道爲什麼rspec用盡了opt/local/bin而不是捆綁包,雖然..

回答

11

我碰到了同樣的問題。在找到所有二進制rspec命令(幾個位置)之後,我遲遲沒有意識到RSPEC的1.3.2分支標題爲它的二進制「spec」而不是「rspec」。

所以正確的命令總是「bundle exec spec specs/models/...」把rspec放在我的當前rvm/gemset中找不到它,然後搜索我的整個路徑,最終出現使用屬於rspec2.x安裝的/ opt/local/bin副本。

一個別名允許rspec 1.3.2也可以響應「rspec」命令是可能的,但對我來說情況並非如此。使用「spec」可以100%可靠地避免rspec-core和其他2.x模塊的調用。

感謝上述問題和所有研究。 Charles

1

它看起來像rspec-core,它來自rspec的一個版本,它只支持Rails 3,可能是問題所在。嘗試卸載並從您的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   
+0

如果我刪除rspec-core,我得到: /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/rubygems_integration。rb:143:在'gem'中:rspec-core不是捆綁的一部分。將它添加到Gemfile。 (Gem :: LoadError) \t from /Users/sys/src/proj/rails/ruby/1.8/bin/rspec:18 – 2011-06-02 15:14:57

+0

我試着卸載所有的rspec寶石,把上面的2個寶石放在你的Gemfile中,然後運行軟件包安裝。 – Mori 2011-06-02 15:18:56

+0

仍然會導致問題。但是,現在它抱怨文件位於/ opt/local/bin/rspec:18中的\t中......該腳本的文件內容是什麼? – 2011-06-02 15:45:49

1

A bundle update rspec-rails在rails 3.1上爲我解決了這個問題。

相關問題