rspec rails - How to check a check box in Capybara test when using simple_form -


trying test functionality in simple page , getting error when using page.check:

    failures:    1) searching stores serving taco , sauce: adobada tacos chile de arbol sauce      failure/error: page.check 'adobada'       capybara::elementnotfound:        unable find checkbox "adobada"      # ./spec/views/store_search_spec.rb:8:in `block (2 levels) in <top (required)>' 

here html:

<%= simple_form_for :stores, url: stores_path, method: :get |f| %>    <%= f.label :tacos, 'select tacos find: ', class: 'label' %>   <div class='taco-select checkboxes'>     <%= f.collection_check_boxes :tacos, taco.order(:name), :id, :name,       :include_hidden => false, :item_wrapper_class => 'checkbox_container' %>   </div>    <%= f.label :salsa, 'select sauces find: ', class: 'label' %>   <div class='salsa-select checkboxes'>     <%= f.collection_check_boxes :salsas, salsa.order(:name), :id, :name,       :include_hidden => false, :item_wrapper_class => 'checkbox_container' %>   </div>    <%= f.submit 'search!' %>  <% end %> 

and test:

require 'rails_helper'  feature 'searching stores', %(serving taco , sauce:)    scenario 'adobada tacos chile de arbol sauce'     visit root_path      page.check 'adobada'     page.check 'chile de arbol'      click_button 'search!'      expect(page).to have_content "store"     expect(page).to have_content 'city'    end end 

i test when checkboxes set true content rendered in page. don't know how fix this.

you don't have use id check checkbox. can use label on checkbox. have checkbox this

<label for="...">   <input type="checkbox" name="...">something</label> 

you 'check' in capybara

it ""   page.check 'something' end 

official docs on can found here


Comments