简体   繁体   English

如何使用 capybara 以简单的形式测试集合输入

[英]How do I test collection input in simple form using capybara

Am trying to test that input which has collection will be filled, am using simple form for my form and capybara with Rspec for the test.this is the input am trying to fill <%= f.input:number_of_beds, collection: House::NUMBEROFBEDS, label: false %> .我正在尝试测试将填充集合的输入,我对我的表单使用简单的表单,并使用带有 Rspec 的水豚进行测试。这是我尝试填充的输入<%= f.input:number_of_beds, collection: House::NUMBEROFBEDS, label: false %>

House model has NUMBEROFBEDS which is an array like so: House model 有 NUMBEROFBEDS ,它是一个像这样的数组:

class House < ApplicationRecord
  NUMBEROFBEDS = [1,2,3,4,5,6]
end

In my spec/system/create_house_spec.rb .在我的spec/system/create_house_spec.rb中。 I tried testing that I can fill in the number_of_beds input like so:我尝试测试我可以像这样填写 number_of_beds 输入:

require "rails_helper"
RSpec.describe "Create House" do
  scenario 'successful house creation' do 
    visit new_house_path
    fill_in 'house_number_of_beds', with: '1'
  end
end

But I get the following error但我收到以下错误

  1) Create House successful bed creation
     Failure/Error: fill_in 'house_number_of_beds', with: '1'

     Capybara::ElementNotFound:
       Unable to find field "house_number_of_beds" that is not disabled

Collection option in simple form, works as select tag , therefore testing it with fill_in is failing the best approach would to use select ie select '1', from: 'house_number_of_beds'简单形式的收集选项,用作select tag ,因此使用fill_in对其进行测试失败的最佳方法是使用 select 即select '1', from: 'house_number_of_beds'

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

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