简体   繁体   English

Rspec水豚以简单的形式

[英]Rspec Capybara on simple form

I am starting to test my app and I am stuck on the user register form... 我开始测试我的应用,并且被卡在用户注册表格中...

  h2 Sign up
  = simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
    = f.error_notification
    .form-inputs
      = f.input :first_name, required: true, autofocus: true
      = f.input :last_name, required: true
      = f.input :nickname, required: true
      = f.input :email, required: true
      = f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length)
      = f.input :password_confirmation, required: true
    .form-actions

      =f.button :submit , class:'btn btn-primary'

I am following an exemple like this one: 我正在遵循这样的一个例子:

describe "Signing up " do
  it "allows a user to sign up for the site and create object in the database" do
    expect(User.count).to eq(0)

    visit "/en/users/sign_up"
    expect(page).to have_content("Sign up")
    fill_in "First Name", with: "John"
    fill_in "Last Name", with: "Doe"
    fill_in "Nickname", with: "JD"
    fill_in "Email", with: "john@email.com"
    fill_in "Password", with: "password"
    fill_in "Password (again)", with: "password"
    click_button "Create User"

    expect(User.count).to eq(1)
    #

  end
end

I dont know how to test the simple form labels?I tried with adding an id to: 我不知道如何测试简单的表单标签?我尝试在其中添加ID

= f.input :first_name, required: true, autofocus: true, id: "first_name"

and the in the spec: 和规范中:

fill_in "first_name", with: "John"

It doesn't make the job... What should I do ? 它没有工作...我该怎么办?

Found a hint here 在这里找到提示

fill_in "user_first_name", with: "John" works :) fill_in "user_first_name", with: "John" :)

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

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