2017-03-31 03:55:46 -04:00
|
|
|
# rubocop:disable Style/GlobalVars
|
2015-04-25 14:33:04 -04:00
|
|
|
require 'capybara/rails'
|
|
|
|
require 'capybara/rspec'
|
|
|
|
require 'capybara/poltergeist'
|
2016-12-07 22:45:34 -05:00
|
|
|
require 'capybara-screenshot/rspec'
|
2015-04-25 14:33:04 -04:00
|
|
|
|
|
|
|
# Give CI some extra time
|
2017-03-31 03:55:46 -04:00
|
|
|
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 60 : 30
|
2015-04-25 14:33:04 -04:00
|
|
|
|
|
|
|
Capybara.javascript_driver = :poltergeist
|
|
|
|
Capybara.register_driver :poltergeist do |app|
|
2016-11-28 03:50:08 -05:00
|
|
|
Capybara::Poltergeist::Driver.new(
|
|
|
|
app,
|
|
|
|
js_errors: true,
|
|
|
|
timeout: timeout,
|
|
|
|
window_size: [1366, 768],
|
2017-06-08 05:55:07 -04:00
|
|
|
url_whitelist: %w[localhost 127.0.0.1],
|
|
|
|
url_blacklist: %w[.mp4 .png .gif .avi .bmp .jpg .jpeg],
|
2016-11-28 03:50:08 -05:00
|
|
|
phantomjs_options: [
|
2017-06-08 05:55:07 -04:00
|
|
|
'--load-images=yes'
|
2016-11-28 03:50:08 -05:00
|
|
|
]
|
|
|
|
)
|
2015-04-25 14:33:04 -04:00
|
|
|
end
|
|
|
|
|
2016-03-15 14:03:17 -04:00
|
|
|
Capybara.default_max_wait_time = timeout
|
2015-04-25 14:33:04 -04:00
|
|
|
Capybara.ignore_hidden_elements = true
|
|
|
|
|
2016-12-07 22:45:34 -05:00
|
|
|
# Keep only the screenshots generated from the last failing test suite
|
|
|
|
Capybara::Screenshot.prune_strategy = :keep_last_run
|
2016-01-28 20:45:03 -05:00
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2017-03-31 03:55:46 -04:00
|
|
|
config.before(:context, :js) do
|
|
|
|
next if $capybara_server_already_started
|
|
|
|
|
2017-03-30 10:30:05 -04:00
|
|
|
TestEnv.eager_load_driver_server
|
2017-03-31 03:55:46 -04:00
|
|
|
$capybara_server_already_started = true
|
2016-01-28 20:45:03 -05:00
|
|
|
end
|
2017-06-16 11:23:49 -04:00
|
|
|
|
2017-06-21 22:38:16 -04:00
|
|
|
config.after(:each, :js) do |example|
|
2017-06-16 11:23:49 -04:00
|
|
|
# capybara/rspec already calls Capybara.reset_sessions! in an `after` hook,
|
|
|
|
# but `block_and_wait_for_requests_complete` is called before it so by
|
|
|
|
# calling it explicitely here, we prevent any new requests from being fired
|
|
|
|
# See https://github.com/teamcapybara/capybara/blob/ffb41cfad620de1961bb49b1562a9fa9b28c0903/lib/capybara/rspec.rb#L20-L25
|
2017-06-21 22:38:16 -04:00
|
|
|
# We don't reset the session when the example failed, because we need capybara-screenshot to have access to it.
|
|
|
|
Capybara.reset_sessions! unless example.exception
|
2017-06-16 11:23:49 -04:00
|
|
|
block_and_wait_for_requests_complete
|
|
|
|
end
|
2016-01-28 20:45:03 -05:00
|
|
|
end
|