水豚:未定义的方法'访问' [英] Capybara: undefined method 'visit'

查看:42
本文介绍了水豚:未定义的方法'访问'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用rspec&运行我的规格时水豚,找不到水豚的造访方法。我还需要执行另一个初始化步骤吗?

When running my specs with rspec & capybara, it can't find capybara's visit method. Is there another initialization step I need to do?

$bundle exec rspec spec
/home/brian/projects/expense_track/expense_track/spec/requests/homepage_spec.rb:6:in `block (2 levels) in <top (required)>': undefined method `visit' for #<Class:0xb6572b8> (NoMethodError)

Gemfile:

group :test, :development do
  gem "rspec-rails"
  gem "capybara"
end

我的spec_helper.rb的顶部:

top of my spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)

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

homepage_spec.rb:

homepage_spec.rb:

require 'spec_helper'

describe "The home page" do

  context "home page exists" do
    visit "/"
    page.should have_content("elephants")
  end
end


推荐答案

所以其原因是水豚有一些未记录的变化。 Capybara现在假设使用它的任何东西都必须位于 spec / features 文件夹中,并且它将进行正确的假设。 spec / requests 文件夹中的所有内容将不再起作用。尽管有解决方法。

So the reason for this is there has been a somewhat undocumented change in Capybara. Capybara now makes the assumption that anything using it needs to be in the spec/features folder and it will make the proper assumptions. Anything left in the spec/requests folder will no longer work. Though there are workarounds.

对于上下文块,可以添加参数:type =>。 :feature ,这将解决该问题,或者您可以将规范开头的描述方法的名称更改为功能,这也应该对其进行更改。

For a context block you can add the parameter :type => :feature and this will fix that issue or you can change the name of a describe method at the beginning of a spec to feature and this should change it as well.

他们在Google网上论坛中宣布了此更改:https://groups.google.com/forum/?fromgroups=#!topic/ruby-capybara/5KfxezI-U0Q

They announced this change in their Google group: https://groups.google.com/forum/?fromgroups=#!topic/ruby-capybara/5KfxezI-U0Q


值得注意的是,我们将Capybara假定您的规格在RSpec中运行的:type更改为:feature(以前是:请求)。最新版本的规格/功能。或者,您可以使用Capybara Feature DSL(功能而不是describe),它可以正常工作而无需任何其他调整。如果您看到诸如未定义方法访问之类的错误,则可能是您遇到了此问题。如果要在:request规范中包含模块,则可能需要将其更改为:feature。

Notably, we changed the :type that Capybara assumes your specs run under in RSpec to :feature (previously it was :request). The latest release of spec/features. Alternatively you can use the Capybara Feature DSL (feature instead of describe), which should work without any additional tweaking. If you see errors like undefined method visit, then you're probably encountering this issue. If you're including modules into :request specs, you will probably need to change that to :feature.

github问题: https://github.com/jnicklas/capybara/issues/814

This was further discussed in the github issue: https://github.com/jnicklas/capybara/issues/814

这篇关于水豚:未定义的方法'访问'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆