Last active
August 29, 2015 14:09
-
-
Save jodosha/47a88c2803da6a8055d1 to your computer and use it in GitHub Desktop.
RSpec features helper for AJAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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