From 076f24308a04239aaa64ca8b895c8fe5d87ca454 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Sun, 26 Dec 2021 06:27:52 +0000 Subject: [PATCH] Manage browser drivers with webdriver gem --- .circleci/config.yml | 4 ++-- Gemfile | 1 + Gemfile.lock | 5 +++++ bin/setup | 5 ----- spec/spec_helper.rb | 4 ---- spec/support/webmock.rb | 11 +++++++++++ 6 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 spec/support/webmock.rb diff --git a/.circleci/config.yml b/.circleci/config.yml index 056dab95c4..156fbe70e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,7 +48,7 @@ jobs: ruby-26: <<: *default_job docker: - - image: circleci/ruby:2.6.3-node-browsers-legacy + - image: circleci/ruby:2.6.3-browsers environment: PGHOST: localhost PGUSER: administrate @@ -62,7 +62,7 @@ jobs: ruby-27: <<: *default_job docker: - - image: circleci/ruby:2.7-node-browsers-legacy + - image: circleci/ruby:2.7-browsers environment: PGHOST: localhost PGUSER: administrate diff --git a/Gemfile b/Gemfile index b677a321c9..0bdbdad652 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ group :test do gem "selenium-webdriver" gem "shoulda-matchers" gem "timecop" + gem "webdrivers" gem "webmock" gem "xpath", "3.2.0" end diff --git a/Gemfile.lock b/Gemfile.lock index 1d6cfdbbed..7db6c40cdb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -304,6 +304,10 @@ GEM unicorn (6.0.0) kgio (~> 2.6) raindrops (~> 0.7) + webdrivers (5.0.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0) webmock (3.14.0) addressable (>= 2.8.0) crack (>= 0.3.2) @@ -352,6 +356,7 @@ DEPENDENCIES timecop uglifier unicorn + webdrivers webmock xpath (= 3.2.0) yard diff --git a/bin/setup b/bin/setup index d39fed70a9..bac8ad9741 100755 --- a/bin/setup +++ b/bin/setup @@ -23,11 +23,6 @@ bundle exec rake db:setup dev:prime # Add binstubs to PATH via export PATH=".git/safe/../../bin:$PATH" in ~/.zshenv mkdir -p .git/safe -if ! command -v chromedriver > /dev/null; then - printf 'chromedriver is not installed.\n' - printf 'See https://chromedriver.chromium.org for install instructions.\n' -fi - # Only if this isn't CI # if [ -z "$CI" ]; then # fi diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 582d843966..bf7687ba2b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,3 @@ -require "webmock/rspec" - # http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| config.expect_with :rspec do |expectations| @@ -12,5 +10,3 @@ config.order = :random end - -WebMock.disable_net_connect!(allow_localhost: true) diff --git a/spec/support/webmock.rb b/spec/support/webmock.rb new file mode 100644 index 0000000000..dbca72cb87 --- /dev/null +++ b/spec/support/webmock.rb @@ -0,0 +1,11 @@ +require "webmock/rspec" + +# Allow downloading webdrivers for Selenium +driver_hosts = Webdrivers::Common.subclasses. + map { |driver| URI(driver.base_url).host } + +# Downloading the Firefox driver involves a redirect +driver_hosts += ["github-releases.githubusercontent.com"] + +# Additionally, avoid conflict with Selenium (localhost) +WebMock.disable_net_connect!(allow_localhost: true, allow: driver_hosts)