Ruby on rails 在utility.rb中注册实用程序测试方法的调用失败
我对在Rails上编写测试有点陌生,现在我正在学习RoR教程。我正在尝试添加我自己的测试实用程序方法sign_up,类似于utility.rb中已有的sign_in方法。但是,当在我的注册页面上调用它时,我遇到以下错误:Ruby on rails 在utility.rb中注册实用程序测试方法的调用失败,ruby-on-rails,railstutorial.org,Ruby On Rails,Railstutorial.org,我对在Rails上编写测试有点陌生,现在我正在学习RoR教程。我正在尝试添加我自己的测试实用程序方法sign_up,类似于utility.rb中已有的sign_in方法。但是,当在我的注册页面上调用它时,我遇到以下错误: 2) User pages index pagination as an admin user to unlock new users Failure/Error: sign_up user Capybara::ElementNotFound:
2) User pages index pagination as an admin user to unlock new users
Failure/Error: sign_up user
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/support/utilities.rb:33:in `sign_up'
# ./spec/requests/user_pages_spec.rb:63:in `block (5 levels) in <top (required)>'
它似乎开始出错,甚至只是访问注册路径-我甚至不确定它会去那里。此外,如果我注释掉fill\u in“Name”
行,它将以同样的方式阻塞fill\u in“Email”
行
如果您对这里发生的事情有任何建议或想法,我们将不胜感激
谢谢,
-马特,灯泡终于亮了 使用工厂创建用户时,它会将其插入数据库中。因此,当您转到注册页面并尝试使用该用户时,它已经存在,您将被重定向到主页。这意味着不存在可用于填充的字段。简化规格:
require 'spec_helper'
describe "signup page" do
subject { page }
describe "with valid information" do
before { sign_up('em', 'em@em.com', '123456') }
it { should have_title_and_h1('em') }
end
end
实用方法:
def sign_up(name, email, password)
visit signup_path
fill_in "Name", with: name
fill_in "Email", with: email
fill_in "Password", with: password
fill_in "Confirmation", with: password
click_button "Create my account"
end
将通过浏览器界面创建用户
def sign_up(name, email, password)
visit signup_path
fill_in "Name", with: name
fill_in "Email", with: email
fill_in "Password", with: password
fill_in "Confirmation", with: password
click_button "Create my account"
end