2011-04-20 89 views
4

我在使用Rspec 1.3的rails 2.3.8應用程序中設置水豚(0.4.1.2)時遇到了一些麻煩從安裝水豚指令我插入了行:安裝Capybara for Rails 2.3和Rspec

require 'capybara/rspec' 

但是,這給了我一個不斷的錯誤。似乎它正在尋找一個沒有加載的類「RSpec」(我猜這是一個RSpec 2/Rails 3的東西)。

那麼如何讓Rspec在rails 2.3下識別水豚?我應該使用較早版本的capy?

PS。這裏的回溯的一個片段:

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|443| in `load_missing_constant': uninitialized constant RSpec (NameError) 

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|80| in `const_missing_not_from_s3_library' 

/Users/rafe/.rvm/gems/[email protected]/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb|206| in `const_missing' 

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|92| in `const_missing' 

|| from /Users/rafe/.rvm/gems/[email protected]/gems/capybara-0.4.1.2/lib/capybara/rspec.rb:4 


/Users/rafe/.rvm/gems/[email protected]/gems/rails-2.3.5/lib/rails/gem_dependency.rb|119| Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement 

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|443| in `load_missing_constant': uninitialized constant RSpec (NameError) 

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|80| in `const_missing_not_from_s3_library' 

/Users/rafe/.rvm/gems/[email protected]/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb|206| in `const_missing' 

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|92| in `const_missing' 

| from /Users/rafe/.rvm/gems/[email protected]/gems/capybara-0.4.1.2/lib/capybara/rspec.rb:4 

/Users/rafe/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb|31| in `gem_original_require' 

/Users/rafe/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb|31| in `require' 

/Users/rafe/.rvm/gems/[email protected]/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|158| in `require' 

|| from /Users/rafe/cmi/lci/branches/forums/spec/spec_helper.rb:12 

回答

5

水豚沒有內置的支持RSpec的1.x的但是,您可以使用Steak而不是滾動您自己的RSpec支持。

3

從水豚DOC,

Note that Capybara’s built in RSpec support only works with RSpec 2.0 or later. You’ll need to roll your own for earlier versions of RSpec.

5

如果你只是想要做'請求規範'(就像在railscasts的「我如何測試」中定義的那樣),它似乎並不是真的需要牛排。 另見:What does Steak add beyond just using Capybara and RSpec in Rails testing?

我剛剛建立了軌2.3 + rspec的1個+水豚(最新版本),在這裏和那裏沒有任何麻煩

你不能有require capybara/rspec,但似乎一切確實是添加一些匹配器......但真正重要的是水豚和DSL和驗證的東西

水豚可與任何機架應用

spec_helper.rb

require 'capybara/rails' 
include Capybara::DSL 

,這就是它 (正好砸在文檔的水豚,它的DSL因爲一些RSpec中,水豚的匹配可能會丟失,沒有什麼會被阻擋,壽)

+0

我收到此錯誤:未初始化的常量水豚:: DSL(NameError) – RAJ 2012-07-24 11:50:48

+1

我建議在你的spec_helper.rb上進行一些調試... 我認爲這可能是因爲我們已經在這個rails 2.3項目上使用了bundler,所以Bundler可能會要求水豚自動爲我... 看看Capybara文檔,看看哪些文件需要水豚/ dsl,也許'需要'capybara''頂部spec_helper.rb wil我做的訣竅 – 2012-07-25 15:11:03

+1

這對我來說很好,謝謝 – 2012-10-08 20:51:11