We have a race condition between click_link and reload_page. Sometimes the AJAX call will go through before Capybara reloads the page, and sometimes it won’t. This kind of nondeterministic test can be very difficult to debug, so I added a little helper. Capybara’s Little Helper Here’s the helper, via Coderwall: # spec/support/wait_for_ajax.rb module WaitForAjax def wait_for_ajax Timeout.timeout(Ca
![Automatically Wait for AJAX with Capybara](https://cdn-ak-scissors.b.st-hatena.com/image/square/beac31a4be8e4962e2fefc94fd70b667eb3e9cec/height=288;version=1;width=512/https%3A%2F%2Fimages.thoughtbot.com%2Fblog-images%2Fsocial-share-default.png)