ruby-on-rails – 为什么水豚不能提供请求规格?

使用rspec和capybara处理新的Rails 3.2.9应用程序.

我在Gemfile中有以下内容

gem 'rspec-rails'
gem 'capybara'

以及spec / spec_helper.rb中的以下内容

require 'rspec/rails'
require 'capybara/rspec'

并在spec / requests / asdf_spec.rb中:

require 'spec_helper'
describe 'Asdf' do
  describe "GET /asdfs" do
    it "should list asdfs" do
      visit asdfs_path
    end
  end
end

此测试失败:

Failure/Error: visit asdfs_path
NoMethodError:
 undefined method `visit' for #<RSpec::Core::ExampleGroup::nested_1::nested_2::nested_1:0x007fa7b68961a0>
# ./spec/requests/asdfs_spec.rb:19:in `block (4 levels) in <top (required)>'

所以看起来Capybara没有加载.伙计,为什么不呢?我觉得我之前已经完成了十几次同样的事情……可能会对一些愚蠢的东西进行消隐.

解决方法

所以这是一个水豚版2改变.我找到了这个:

http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html

这解释了:

Upon upgrading to capybara 2.0,capybara will not be available by
default
in RSpec request specs. Instead,a new type of spec–the
feature spec–has been created for use with capybara.

To upgrade to capybara 2.0,you’ll need to do a few things:

  • Upgrade rspec-rails to 2.12.0 or greater
  • Move any tests that use capybara from spec/requests to spec/features. Capybara tests use the visit method and usually assert against page.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...