forked from igorman/data-engineering
/
test_helper_integration.rb
53 lines (39 loc) · 1.19 KB
/
test_helper_integration.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
require "test_helper"
require "capybara/rails"
Capybara.default_driver = :poltergeist
module ActionDispatch
class IntegrationTest
include Capybara::DSL
before { set_page_size_to_13inch_macbook_air }
after { capybara_reset_sessions! }
protected
def set_page_size_to_13inch_macbook_air
page.driver.resize 1440, 900
end
def capybara_reset_sessions!
Capybara.reset_sessions!
end
def capybara_response_body
Capybara.current_session.driver.body
end
def save_and_open_page
dir = "#{Rails.root}/tmp/cache/capybara"
file = "#{dir}/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.png"
FileUtils.mkdir_p dir
page.driver.render file
wait_until { File.exists?(file) }
system "open #{file}"
end
def wait_for_selector(selector)
wait_until { has_css?(selector) }
rescue Capybara::TimeoutError
flunk "Ran out of time waiting for this selector: #{selector.inspect}"
end
end
end
# If you want to use transitional fixtures and force all threads to 1 DB connection.
class ActiveRecord::Base
def self.connection
@@shared_connection ||= retrieve_connection
end
end