Skip to content

Instantly share code, notes, and snippets.

@s0kil
Last active January 11, 2021 15:10
Show Gist options
  • Save s0kil/43c247893ea74d7a293018a498ad9a9d to your computer and use it in GitHub Desktop.
Save s0kil/43c247893ea74d7a293018a498ad9a9d to your computer and use it in GitHub Desktop.
RSpec, Capybara JavaScript Driver (https://github.com/twalpole/apparition)
require 'capybara/apparition'
Capybara.server = :puma, { Silent: true }
Capybara.register_driver :chrome_headless do |app|
Capybara::Apparition::Driver.new(app, { headless: true, browser_options: { 'headless': '', 'no-sandbox': '' } })
end
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox])
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
RSpec.configure do |config|
config.before(:all, type: :feature) do
Capybara.default_driver = :chrome
end
config.before(:all, type: :system) do
driven_by(:chrome_headless)
end
end
@s0kil
Copy link
Author

s0kil commented Jan 10, 2021

Create a spec/support/drivers.rb file with above contents, and then require it into your spec/rails_helper.rb file.
See it in practice here https://github.com/danielsokil/nutrire/blob/develop/spec/rails_helper.rb

You will also need gem 'capybara' and gem 'apparition' in your Gemfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment