Initial Setup: Capybara and Poltergeist
To set up Capybara and Poltergeist, add them both to your gemfile and add the following lines to your test helper.
Ajax Test Failures
I quickly found that Capybara was not always waiting for Ajax requests to complete. Ryan Bigg had a similar problem, but I was unable to get his solution to work. I came up with a kludge using HTML attributes. I set a waiting attribute to be true, wait for the ajaxSuccess event to be fired, and then set the waiting attribute to be false. The loop will not break until this attribute is set to false or it times out.