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

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的Ruby相关文章