加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 04:18:53 所属栏目:百科 来源:网络整理
导读:使用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
使用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读