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 i.e
select '1', from: 'house_number_of_beds'