Merge branch '2733-coverage-report'
[arvados.git] / apps / workbench / test / integration_helper.rb
1 require 'test_helper'
2 require 'capybara/rails'
3 require 'capybara/poltergeist'
4 require 'uri'
5 require 'yaml'
6
7 class ActionDispatch::IntegrationTest
8   # Make the Capybara DSL available in all integration tests
9   include Capybara::DSL
10   include ApiFixtureLoader
11
12   @@API_AUTHS = self.api_fixture('api_client_authorizations')
13
14   def page_with_token(token, path='/')
15     # Generate a page path with an embedded API token.
16     # Typical usage: visit page_with_token('token_name', page)
17     # The token can be specified by the name of an api_client_authorizations
18     # fixture, or passed as a raw string.
19     api_token = ((@@API_AUTHS.include? token) ?
20                  @@API_AUTHS[token]['api_token'] : token)
21     sep = (path.include? '?') ? '&' : '?'
22     q_string = URI.encode_www_form('api_token' => api_token)
23     "#{path}#{sep}#{q_string}"
24   end
25
26   # Find a page element, but return false instead of raising an
27   # exception if not found. Use this with assertions to explain that
28   # the error signifies a failed test rather than an unexpected error
29   # during a testing procedure.
30   def find? *args
31     begin
32       find *args
33     rescue Capybara::ElementNotFound
34       false
35     end
36   end
37 end