require "selenium/webdriver"

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new
  options.headless!
  options.add_argument "--window-size=1680,1050"

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    options: options
end

Capybara.javascript_driver = :headless_chrome

require "selenium/webdriver"

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new
  options.headless!
  options.add_argument "--window-size=1680,1050"

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    options: options
end

Capybara.javascript_driver = :headless_chrome

RSpec.configure do |config|
  config.before(:each, type: :system) do
    driven_by :rack_test
  end

  config.before(:each, type: :system, js: true) do
    driven_by Capybara.javascript_driver
  end
end

Configure System Test drivers with `driven_by`
Configure System Test drivers with `driven_by`

According to the documentation from [`rspec-rails`][rspec-rails]:

> RSpec **does not** use your `ApplicationSystemTestCase` helper.
> Instead it uses the default `driven_by(:selenium)` from Rails. If you
> want to override this behaviour you can call `driven_by` manually in a
> test.

This commit introduces an [`RSpec.configure`][configure] block which
sets the default driver for `type: :system` tests by invoking
[`driven_by`][driven_by] with [`:rack_test`][rack_test].

To opt into JavaScript-enabled tests, set the `js: true` (or `:js`)
metadata on a `describe`, `context`, or `it` block.

[driven_by]: https://api.rubyonrails.org/v6.0/classes/ActionDispatch/SystemTestCase.html#method-c-driven_by
[rspec-rails]: https://relishapp.com/rspec/rspec-rails/v/3-9/docs/system-specs/system-spec
[configure]: https://relishapp.com/rspec/rspec-core/docs/configuration/custom-settings#simple-setting-(with-defaults)
[rack_test]: https://github.com/rack-test/rack-test
