You need to use a JS-enabled driver for your test. If you are using webrat o capybara you can try using selenium.
Then I should see "foo"
This doesn't work using the default web step because the DOM has not been updated when it looks for the text. There are 2 options:
Option 1: Wait
And I wait for 1 second
Then I should see "foo"
You need to implement this step to call sleep(n)
Option 2: Custom locate
Capybara's locate method will see if the target is present in the DOM. If not it will wait for a few seconds and try again and throw an error if it's still not present.
Then I should see the following autocomplete options:
| foo |
This is how the implementation of the steps looks like for me:
Then /^I should see the following autocomplete options:$/ do |table|
table.raw.each do |row|
locate(:xpath, "//a[text()='#{row[0]}']")
end
end
If you need more detailed information on this subject I have written a blogpost with examples and some snippets, also dealing with clicking the autocomplete options presented:
http://www.aentos.com/blog/testing-ajax-autocomplete-fields-cucumber-and-capybara