我对在 Rails 上编写测试有点陌生,我正在关注http://ruby.railstutorial.org上的 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:
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)>'
我的 sign_up 方法如下所示:
def sign_up(user)
visit signup_path
fill_in "Name", with: user.name
fill_in "Email", with: user.email
fill_in "Password", with: user.password
fill_in "Confirmation", with: user.password
click_button "Sign up"
end
即使只是访问 signup_path 似乎也开始出错 - 我什至不确定它是否会去那里。此外,如果我注释掉这fill_in "Name"
条线,它也会以同样的方式扼杀这fill_in "Email"
条线。
任何关于这里发生的事情的建议或想法将不胜感激。
谢谢,-马特