gitlab-org--gitlab-foss/spec/support/capybara.rb
Rémy Coutable abc5d1d0a5
Call Capybara.reset_sessions! before block_and_wait_for_requests_complete
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
ffb41cfad6/lib/capybara/rspec.rb (L20-L25)

Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-06-16 17:23:49 +02:00

47 lines
1.4 KiB
Ruby

# rubocop:disable Style/GlobalVars
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'capybara-screenshot/rspec'
# Give CI some extra time
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 60 : 30
Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(
app,
js_errors: true,
timeout: timeout,
window_size: [1366, 768],
url_whitelist: %w[localhost 127.0.0.1],
url_blacklist: %w[.mp4 .png .gif .avi .bmp .jpg .jpeg],
phantomjs_options: [
'--load-images=yes'
]
)
end
Capybara.default_max_wait_time = timeout
Capybara.ignore_hidden_elements = true
# Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run
RSpec.configure do |config|
config.before(:context, :js) do
next if $capybara_server_already_started
TestEnv.eager_load_driver_server
$capybara_server_already_started = true
end
config.after(:each, :js) do
# 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
Capybara.reset_sessions!
block_and_wait_for_requests_complete
end
end