Module: Softwear::Lib::Spec::CapybaraHelpers

Defined in:
lib/softwear/lib/spec.rb

Instance Method Summary collapse

Instance Method Details

#accept_alertObject



36
37
38
39
# File 'lib/softwear/lib/spec.rb', line 36

def accept_alert
  page.evaluate_script('window.confirm = function() { return true; }')
  yield
end

#dismiss_alertObject



41
42
43
44
45
46
# File 'lib/softwear/lib/spec.rb', line 41

def dismiss_alert
  page.evaluate_script('window.confirm = function() { return false; }')
  yield
  # Restore existing default
  page.evaluate_script('window.confirm = function() { return true; }')
end

#finished_all_ajax_requests?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/softwear/lib/spec.rb', line 19

def finished_all_ajax_requests?
  page.evaluate_script('jQuery.active').zero?
end

#wait_for_ajaxObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/softwear/lib/spec.rb', line 8

def wait_for_ajax
  begin
    Timeout.timeout(Capybara.default_wait_time) do
      wait_for_jquery
      loop until finished_all_ajax_requests?
    end
  rescue
    sleep 0.1
  end
end

#wait_for_jqueryObject



30
31
32
33
34
# File 'lib/softwear/lib/spec.rb', line 30

def wait_for_jquery
  until page.evaluate_script('jQuery.active') == 0
    sleep(0.1)
  end
end

#wait_for_redirectObject



23
24
25
26
27
28
# File 'lib/softwear/lib/spec.rb', line 23

def wait_for_redirect
  original_url = current_path
  until current_path != original_url
    sleep(0.1)
  end
end