docbrown/spec/support/initializers/capybara.rb
dependabot[bot] 609afc71c7
Bump rubocop from 1.15.0 to 1.16.0 (#13894)
* Bump rubocop from 1.15.0 to 1.16.0

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.15.0...v1.16.0)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Enable new cops and fix violations

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: rhymes <github@rhymes.dev>
2021-06-02 09:11:38 -04:00

46 lines
1.5 KiB
Ruby

require "capybara/rails"
require "capybara/rspec"
require "webdrivers/chromedriver"
Webdrivers.cache_time = 86_400
Capybara.default_max_wait_time = 10
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
if ENV["SELENIUM_URL"].present?
# Support use of remote chrome testing.
Capybara.server_host = ENV.fetch("CAPYBARA_SERVER_HOST") { "0.0.0.0" }
ip = Socket.ip_address_list.detect(&:ipv4_private?).ip_address
host! URI::HTTP.build(host: ip, port: Capybara.server_port).to_s
driven_by :selenium, using: :chrome, screen_size: [1400, 2000], options: { url: ENV["SELENIUM_URL"] }
else
# options from https://github.com/teamcapybara/capybara#selenium
chrome = ENV["HEADLESS"] == "false" ? :selenium_chrome : :selenium_chrome_headless
driven_by chrome
end
end
end
# rubocop:disable Style/TopLevelMethodDefinition
# adapted from <https://medium.com/doctolib-engineering/hunting-flaky-tests-2-waiting-for-ajax-bd76d79d9ee9>
def wait_for_javascript
max_time = Capybara::Helpers.monotonic_time + Capybara.default_max_wait_time
finished = false
while Capybara::Helpers.monotonic_time < max_time
finished = page.evaluate_script("typeof initializeBaseApp") != "undefined"
break if finished
sleep 0.1
end
raise "wait_for_javascript timeout" unless finished
end
# rubocop:enable Style/TopLevelMethodDefinition