Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Last active December 16, 2015 13:29
Show Gist options
  • Save the-teacher/5441852 to your computer and use it in GitHub Desktop.
Save the-teacher/5441852 to your computer and use it in GitHub Desktop.
Capybara 2.0 Wait for ajax
require "timeout"
module WaitForAjax
def self.delay
@delay || 1
end
def self.delay= val
@delay = val
end
def self.max_time
@max_time || 10
end
def self.max_time= val
@max_time = val
end
def wait_for_ajax &block
begin
Timeout.timeout(WaitForAjax.max_time) do
sleep(WaitForAjax.delay) and print '.' until value = yield
print "\n"
value
end
rescue TimeoutError
false
end
end
end
# WaitForAjax.max_time = 20
# WaitForAjax.delay = 0.5
# wait_for_ajax{ [true, false, false, false, false, false, false, false, false].sample }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment