简体   繁体   English

水豚:未定义的方法'访问'-测试已经在规格/功能中

[英]Capybara: undefined method 'visit' - Test is already in spec/features

I have just started with RSpec and Capybara but got stuck on my first test. 我刚开始使用RSpec和Capybara,但是在我的第一个测试中遇到了困难。 Here's me test code located in spec/features/pages_spec.rb : 这是我位于spec/features/pages_spec.rb测试代码:

require 'rails_helper'

RSpec.describe "Pages", :type => :request do
    describe "About Page" do
        it "should have the content 'About Us'" do
            visit '/pages/about'
            page.should have_content('About Us')
        end
    end
end

Running the test i get the following error : 运行测试我得到以下错误:

01:06:59 - INFO - Running: spec

F

Failures:

1) Pages About Page should have the content 'About Us'
 Failure/Error: visit '/pages/about'
 NoMethodError:
   undefined method 'visit' for #<RSpec::ExampleGroups::Pages::AboutPage:0x007f975afe7380>
 # ./spec/features/pages_spec.rb:6:in `block (3 levels) in <top (required)>'
 # ./spec/rails_helper.rb:44:in `block (3 levels) in <top (required)>'
 # ./spec/rails_helper.rb:43:in `block (2 levels) in <top (required)>'

Finished in 0.02569 seconds (files took 1.65 seconds to load)

1 example, 1 failure

Failed examples:
rspec ./spec/features/pages_spec.rb:5 # Pages About Page should have the content 'About Us'

I've been searching about this for about an hour and everywhere I find the solution of moving the test code from spec/requests to spec/features . 我已经搜索了大约一个小时,并且到处都可以找到将测试代码从spec/requests移到spec/features的解决方案。

I've also seen this here : http://www.rubydoc.info/gems/rspec-rails/file/Capybara.md which most of the solution suggests and it is not recommended to use. 我在这里也看到了这一点: http : //www.rubydoc.info/gems/rspec-rails/file/Capybara.md ,大多数解决方案都建议这样做,不建议使用。

# not recommended!
RSpec.configure do |c|
    c.include Capybara::DSL, :file_path => "spec/requests"
end

I've no idea how to proceed. 我不知道该如何进行。 Your help will be appreciated. 您的帮助将不胜感激。

从描述块中取出:type => :request (覆盖从目录位置确定的规范类型),或将其更改为:type => :feature

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM