为Rails 2.3和Rspec设置Capybara



我在Rspec 1.3的rails 2.3.8应用程序中设置capybara(0.4.1.2)遇到了一些麻烦,从安装capybara的说明中,我插入了以下行:

require 'capybara/rspec' 

然而,这给了我一个缺失的常数错误。似乎它正在寻找一个类'RSpec'没有加载(我猜这是一个RSpec 2/Rails 3的东西)。

那么我如何让Rspec在rails 2.3下识别水豚呢?我应该使用早期版本的capy吗?

p。下面是反向跟踪的一个片段:

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|443| in `load_missing_constant': uninitialized constant RSpec (NameError)
/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|80| in `const_missing_not_from_s3_library'
/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb|206| in `const_missing'
/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|92| in `const_missing'
||  from /Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/capybara-0.4.1.2/lib/capybara/rspec.rb:4

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/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/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|443| in `load_missing_constant': uninitialized constant RSpec (NameError)
/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|80| in `const_missing_not_from_s3_library'
/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb|206| in `const_missing'
/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|92| in `const_missing'
|   from /Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/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/ruby-1.8.6-p399@lci/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

Capybara没有内置对RSpec 1.x的支持。但是,你可以使用Steak来代替你自己的RSpec支持。

如果您只是想做'请求规格'(如railscasts的"我如何测试"中所定义的那样),那么牛排似乎并不真正需要。参见:除了在Rails测试中使用Capybara和RSpec之外,Steak还添加了什么?

我刚刚设置了rails 2.3 + rspec 1 + capybara(最新版本),没有任何麻烦

你不能有require capybara/rspec,但似乎它所做的就是添加一些匹配器…但真正重要的是水豚及其DSL和验证内容

Capybara适用于任何机架应用程序

on my spec_helper.rb:

require 'capybara/rails'
include Capybara::DSL

就是这样(只要点击文档中的Capybara,它是DSL因为某些方面的Capybara匹配器可能会丢失,没有什么会阻塞,虽然)

从Capybara文档,

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.

相关内容

  • 没有找到相关文章

最新更新