Sha256: c4b1dab3b6916f72242a55e2c5267d6b197020855ba1b76e248d778a59edc844

Contents?: true

Size: 797 Bytes

Versions: 2

Compression:

Stored size: 797 Bytes

Contents

module HyperSpec
  module WaitForAjax
    def wait_for_ajax
      Timeout.timeout(Capybara.default_max_wait_time) do
        loop do
          sleep 0.25
          break if finished_all_ajax_requests?
        end
      end
    end

    def running?
      result = page.evaluate_script('(function(active) { return active; })(jQuery.active)')
      result && !result.zero?
    rescue Exception => e
      puts "wait_for_ajax failed while testing state of jQuery.active: #{e}"
    end

    def finished_all_ajax_requests?
      unless running?
        sleep 0.25 # this was 1 second, not sure if its necessary to be so long...
        !running?
      end
    rescue Capybara::NotSupportedByDriverError
      true
    rescue Exception => e
      e.message == 'jQuery is not defined'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyper-spec-0.1.2 lib/hyper-spec/wait_for_ajax.rb
hyper-spec-0.1.0 lib/hyper-spec/wait_for_ajax.rb