为 Rails 2.3 和 Rspec 设置 Capybara

发布于 2024-11-02 15:33:09 字数 2260 浏览 7 评论 0原文

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

require 'capybara/rspec' 

但是,这给了我一个缺失的常量错误。似乎它正在寻找一个未加载的类“RSpec”(我猜这是一个 RSpec 2 / Rails 3 的东西)。

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

附言。这是回溯的片段:

/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

I'm having some trouble setting up capybara (0.4.1.2) in a rails 2.3.8 app with Rspec 1.3 From the installation capybara instructions, I've inserted the line:

require 'capybara/rspec' 

However that gives me a missing constant error. Seems like it's looking for a class 'RSpec' which isn't loaded (I'm guessing that's an RSpec 2 / Rails 3 thing).

So how do I get Rspec to recognize capybara under rails 2.3? Should I use an earlier version of capy?

PS. Here's a snippet of the backtrace:

/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

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

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

发布评论

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

评论(3

梦里人 2024-11-09 15:33:09

Capybara 没有内置对 RSpec 1.x 的支持。但是,您可以使用 Steak 而不是推出自己的 RSpec 支持。

Capybara does not have built in support for RSpec 1.x. However, you can use Steak instead of rolling your own RSpec support.

网白 2024-11-09 15:33:09

如果你只想做“请求规格”(如railscasts的“我如何测试”中所定义),那么似乎并不真正需要牛排。
另请参阅:Steak 是什么除了在 Rails 测试中使用 Capybara 和 RSpec 之外还添加其他内容吗?

我刚刚在这里和那里设置了 Rails 2.3 + rspec 1 + capybara(最新版本)没有任何麻烦,

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

Capybara 可以使用的 任何机架应用

东西我的 spec_helper.rb 上的

require 'capybara/rails'
include Capybara::DSL

:就是这样
(只要点击 Capybara 的文档,它就是 DSL,因为一些 rspec-capybara 匹配器可能会丢失,没有什么会阻塞的,不过)

it seems steak isn't really needed if, say, you just want to do 'request specs'(as defined in railscasts's "how I test").
Also see: What does Steak add beyond just using Capybara and RSpec in Rails testing?

I've just set up rails 2.3 + rspec 1 + capybara(latest version) here and there wasn't any hassle

you can't have require capybara/rspec, but it seems all it does is add some matchers... but what matters really is capybara and its DSL and validating stuff

Capybara works with any rack app

on my spec_helper.rb:

require 'capybara/rails'
include Capybara::DSL

and that's it
(just hit the docs for Capybara and it's DSL because some rspec-capybara matchers may be missing, nothing that would be blocking, tho)

无名指的心愿 2024-11-09 15:33:09

请注意, Capybara

的内置 RSpec 支持仅适用于 RSpec 2.0 或更高版本。您需要为早期版本的 RSpec 自行推出。

From the Capybara 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.

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