簡體   English   中英

水豚:未定義的方法'訪問'-測試已經在規格/功能中

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

我剛開始使用RSpec和Capybara,但是在我的第一個測試中遇到了困難。 這是我位於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

運行測試我得到以下錯誤:

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'

我已經搜索了大約一個小時,並且到處都可以找到將測試代碼從spec/requests移到spec/features的解決方案。

我在這里也看到了這一點: 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

我不知道該如何進行。 您的幫助將不勝感激。

從描述塊中取出:type => :request (覆蓋從目錄位置確定的規范類型),或將其更改為:type => :feature

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM