简体   繁体   中英

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 %> .

House model has NUMBEROFBEDS which is an array like so:

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

In my spec/system/create_house_spec.rb . I tried testing that I can fill in the number_of_beds input like so:

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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