简单形式的Rspec Capybara

时间:2016-10-09 14:33:30

标签: ruby-on-rails ruby-on-rails-4 rspec capybara

我开始测试我的应用程序而且我被困在用户注册表单...

  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'

我正在效仿这样的例子:

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

我不知道如何测试简单的表单标签?我尝试将 id 添加到:

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

和规范:

fill_in "first_name", with: "John"

它没有成功......我该怎么办?

1 个答案:

答案 0 :(得分:1)

找到提示here

fill_in "user_first_name", with: "John"有效:)