【问题标题】:Rspec Capybara on simple form简单形式的 Rspec Capybara
【发布时间】:2016-10-09 14:33:30
【问题描述】:

我开始测试我的应用程序,但卡在用户注册表单上...

  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"

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

【问题讨论】:

  • 您需要查看为页面生成的实际 HTML

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


【解决方案1】:

找到提示here

fill_in "user_first_name", with: "John" 工作:)

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多