2 require 'capybara/rails'
3 require 'capybara/poltergeist'
8 Capybara.default_wait_time = 5
10 Timeout.timeout(Capybara.default_wait_time) do
11 loop until finished_all_ajax_requests?
15 def finished_all_ajax_requests?
16 page.evaluate_script('jQuery.active').zero?
20 class ActionDispatch::IntegrationTest
21 # Make the Capybara DSL available in all integration tests
23 include ApiFixtureLoader
26 @@API_AUTHS = self.api_fixture('api_client_authorizations')
28 def page_with_token(token, path='/')
29 # Generate a page path with an embedded API token.
30 # Typical usage: visit page_with_token('token_name', page)
31 # The token can be specified by the name of an api_client_authorizations
32 # fixture, or passed as a raw string.
33 api_token = ((@@API_AUTHS.include? token) ?
34 @@API_AUTHS[token]['api_token'] : token)
35 sep = (path.include? '?') ? '&' : '?'
36 q_string = URI.encode_www_form('api_token' => api_token)
37 "#{path}#{sep}#{q_string}"
40 # Find a page element, but return false instead of raising an
41 # exception if not found. Use this with assertions to explain that
42 # the error signifies a failed test rather than an unexpected error
43 # during a testing procedure.
47 rescue Capybara::ElementNotFound