/
integration_test_helper.rb
66 lines (53 loc) · 1.65 KB
/
integration_test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require_relative "test_helper"
require "capybara/rails"
Capybara.server = :webrick
Capybara.default_driver = :rack_test
GovukTest.configure
class ActionDispatch::IntegrationTest
include Capybara::DSL
teardown do
Capybara.use_default_driver
end
def assert_page_has_content(text)
assert page.has_content?(text), %(expected there to be content #{text} in #{page.text.inspect})
end
def assert_current_url(path_with_query, options = {})
assert_same_url(current_url, path_with_query, options.merge(wait_until: true))
end
def assert_same_url(expected_url, actual_url, options = {})
expected = URI.parse(expected_url)
wait_until { expected.path == URI.parse(current_url).path } if options[:wait_until]
actual = URI.parse(actual_url)
assert_equal expected.path, actual.path
unless options[:ignore_query]
assert_equal Rack::Utils.parse_query(expected.query), Rack::Utils.parse_query(actual.query)
end
end
# Adapted from http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara
def wait_until
if Capybara.current_driver == Capybara.javascript_driver
begin
Timeout.timeout(Capybara.default_max_wait_time) do
sleep(0.1) until yield
end
rescue Timeout::Error => e
p e
end
end
end
def self.with_javascript
context "with javascript" do
setup do
Capybara.current_driver = Capybara.javascript_driver
end
yield
end
end
def self.without_javascript(&block)
context "without javascript", &block
end
def self.with_and_without_javascript(&block)
without_javascript(&block)
with_javascript(&block)
end
end