diff --git a/.gitignore b/.gitignore index ff93a19e..35ea246e 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,6 @@ nbproject *.iws .idea/ .vagrant/ + +# Ignore chromedriver binary (for test environment) +/bin/chromedriver diff --git a/README.md b/README.md index 3cc3c7c7..592fd358 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,11 @@ get you up and running. 1. [Start hacking](https://railsforzombies.org/) 1. [Test your changes](https://www.relishapp.com/rspec/rspec-core/docs) ```shell - docker-compose exec hackweek rspec + docker compose run hackweek bundle exec rspec ``` + Note: For running tests, use `docker compose run` instead of `docker compose exec`. + The tests require chromedriver for JavaScript/feature tests. Place the chromedriver + binary in `bin/chromedriver` if not already present. 1. [Send pull request](https://help.github.com/articles/using-pull-requests) 1. $UCCE$$ diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7f947e9d..c36577a3 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,6 +1,29 @@ require 'simplecov' + +# Configure webdrivers to not try to download anything +# In sandboxed environments, we assume chromedriver is already available require 'webdrivers' +# Patch Webdrivers to skip network calls +module Webdrivers + class Chromedriver < Common + def self.update + # Skip update in sandboxed environment + nil + end + + def self.install + # Skip install in sandboxed environment + nil + end + + def self.remove + # Skip remove in sandboxed environment + nil + end + end +end + if ENV['TRAVIS'] require 'coveralls' SimpleCov.formatter = Coveralls::SimpleCov::Formatter @@ -37,11 +60,18 @@ Capybara.register_driver :chrome_headless do |app| options = ::Selenium::WebDriver::Chrome::Options.new + options.binary = '/usr/bin/chromium-browser' # Use system chromium options.args << '--window-size=1920x1080' options.args << '--headless' options.args << '--no-sandbox' options.args << '--disable-gpu' - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) + options.args << '--disable-dev-shm-usage' # Overcome limited resource problems + + # Use our local chromedriver to avoid network downloads + chromedriver_path = Rails.root.join('bin/chromedriver').to_s + service = Selenium::WebDriver::Service.chrome(path: chromedriver_path) + + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, service: service) end Capybara.javascript_driver = :chrome_headless