简体   繁体   English

Capybara NoMethodError:未定义的方法`visit'for

[英]Capybara NoMethodError: undefined method `visit' for

Thank for response. 谢谢你的回复。
I getting error in application Git application with the error 我在应用程序Git应用程序中收到错误错误

Failures:

  1) Page pages page creation with invalid information should not create a page
     Failure/Error: before(:each) { visit new_admin_page_path }
     NoMethodError:
       undefined method `visit' for #<Page:0x00000005094bb0>
     # ./spec/requests/page_request_spec.rb:13:in `block (3 levels) in <top (required)>'

  2) Page pages page creation with invalid information error messages 
     Failure/Error: before(:each) { visit new_admin_page_path }
     NoMethodError:
       undefined method `visit' for #<Page:0x000000051671f0>
     # ./spec/requests/page_request_spec.rb:13:in `block (3 levels) in <top (required)>'

Finished in 1.21 seconds
14 examples, 2 failures

What I've missed ? 我错过了什么?

I cloned your repository and ran the spec. 我克隆了您的存储库并运行了规范。 The problem is that you are using the term page for two different things, the Capybara page ( subject { page } ) and your model with the name Page (which you also name page ). 问题是你使用术语page用于两个不同的东西,Capybara页面( subject { page } )和你的模型名称Page (你也命名page )。 Those two names conflict, which is why rspec is complaining that there is no method visit for #<Page:0x00000005094bb0> . 这两个名称冲突,这就是为什么rspec抱怨没有#<Page:0x00000005094bb0>方法visit

To solve this just rename the page you create in the initial let : 要解决此问题,只需重命名您在初始let创建的页面:

let(:mypage) { Factory.create(:page) }

That will avoid the conflict by naming your page model mypage instead of page . 这样可以通过命名页面模型mypage而不是page来避免冲突。

There are other issues however. 但是还有其他问题。 Your user factory does not use a sequence for assigning emails, so you get a validation error because it says the email is already taken. 您的用户工厂不使用序列来分配电子邮件,因此您会收到验证错误,因为它表示电子邮件已被删除。

I changed your user factory to this: 我将您的用户工厂更改为:

sequence(:email) { |n| "abc#{n}@example.com"}
factory :user do
  email
  password "foobar"
  password_confirmation "foobar"
  ...

That fixes the validation error, but you now get another error. 这修复了验证错误,但现在又出现了另一个错误。 In the line in your first spec, you should be checking that count does not change on the class Page , not the record page (or mypage ). 在第一个规范的行中,您应该检查 Page上的count是否没有变化,而不是记录 page (或mypage )。

So change that to: 所以改为:

expect { click_button "Create Page" }.not_to change(Page, :count)

This will still leave you with errors, because you also do not have any create action for your PagesController . 仍然会给您带来错误,因为您还没有对PagesController进行任何create操作。 From what you wrote, it seems like the information is invalid so it should not even get to this action. 从您所写的内容来看,信息似乎无效,因此它甚至不应该采取这种行动。 I don't know exactly what you're trying to do here so I'll leave the rest for you to figure out. 我不知道你到底想要做什么,所以我会留下剩下的让你弄清楚。

If you recently upgraded to Capybara 2.0 & your integration tests were working with previous version of Capybara, you may try renaming requests directory to features. 如果您最近升级到Capybara 2.0并且您的集成测试与以前版本的Capybara一起使用,您可以尝试将请求目录重命名为功能。 Check http://www.codelearn.org/blog/how-to-make-old-integration-tests-work-with-capybara-2-0 查看http://www.codelearn.org/blog/how-to-make-old-integration-tests-work-with-capybara-2-0

Add the following to your spec/spec_helper.rb (in your Spork.prefork block): 将以下内容添加到spec/spec_helper.rb (在Spork.prefork块中):

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

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

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