MARUGOSHI.ORG

Request Spec + Capybara-webkit + Rails3-jquery-autocomplete

This is a tips for not only related with autocomplete but more comprehensive with JavaScipt keydown event. Codes use keydown event, it’s not enough only fill_in, it needs executing keydown event.

it "should enable click tag", js => true do
  fill_in "entry[tag_list]", :with => "ta"
  page.execute_script %Q{ $('#entry_tag_list').trigger("focus") }
  page.execute_script %Q{ $('#entry_tag_list').trigger("keydown") }
  sleep(3)
  selector = '.ui-menu-item a:contains(\"tag name\")'
  page.execute_script " $('#{selector}').trigger(\"mouseenter\").click();"
end