Dimitar Kostov ramblings

Test autocomplete in Rails

Easy way to test autocomplete in RSpec request spec with Capybara

1
2
3
4
5
6
7
8
9
describe 'Description of the spec'
  it "should autocomplete user name", js: true do
    visit users_path
    auto_complete_field = 'user_name'
    fill_in auto_complete_field, with: 'Dimitar'
    page.execute_script %Q{ $('##{auto_complete_field}').trigger("keydown") }
    page.should have_content('Dimitar Kostov')
  end
end
Notice: You should use capybara-webkit driver to enable JavaScript interaction.

Comments