Capybara NoMethodError:的未定义方法“访问” [英] Capybara NoMethodError: undefined method `visit' for

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

问题描述

感谢您的回复。

我在应用程序 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

我错过了什么?

推荐答案

我克隆了您的存储库并运行了规范。问题是,您将术语 page 用于两个不同的东西,即水豚页面(主题{page} )以及名称为 Page 的模型(您也将其命名为 page )。这两个名称冲突,这就是为什么rspec抱怨对于#< Page:0x00000005094bb0> 访问 >。

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). Those two names conflict, which is why rspec is complaining that there is no method visit for #<Page:0x00000005094bb0>.

要解决此问题,只需重命名您在最初的 let 中创建的页面:

To solve this just rename the page you create in the initial let:

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

通过命名页面模型 mypage 而不是 page 。

That will avoid the conflict by naming your page model mypage instead of 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"
  ...

这可以解决验证错误,但现在又遇到另一个错误。在您的第一个规范行中,您应该检查 页面 count 是否不变。 c $ c>,而不是记录 页面(或 mypage )。

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).

因此请将其更改为:

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

这将仍然错误,因为您的 PagesController 也没有任何 create 操作。从您写的内容来看,该信息似乎无效,因此甚至不应该执行此操作。我不知道您要在这里做什么,所以我会把剩下的留给您弄清楚。

This will still leave you with errors, because you also do not have any create action for your PagesController. 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.

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

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