Skip to content

Instantly share code, notes, and snippets.

@jodosha
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jodosha/47a88c2803da6a8055d1 to your computer and use it in GitHub Desktop.
Save jodosha/47a88c2803da6a8055d1 to your computer and use it in GitHub Desktop.
RSpec features helper for AJAX
# Credits:
#
# * http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
# * https://coderwall.com/p/aklybw
require 'timeout'
module RSpec::Features
module AjaxHelpers
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
loop until finished_all_ajax_requests?
end
end
private
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
end
__END__
Usage:
feature 'Visit home page' do
include RSpec::Features::AjaxHelpers
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment