smashingboxes / boxcar-generator-archive

A tool for generating Rails applications with the best practices of the Smashing Boxes team.
MIT License
16 stars 2 forks source link

Update capybara configs #156

Open dkniffin opened 5 years ago

dkniffin commented 5 years ago

Instead of requiring chromedriver to be installed globally, we should add the webdrivers gem, and change our capybara config to this:

# frozen_string_literal: true

require "webdrivers"

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu] }
  )

  Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end

RSpec.configure do |config|
  config.include Capybara::DSL

  config.after do
    Capybara.reset_sessions!
  end

  config.before(:each, type: :system) do
    driven_by :headless_chrome
  end
end

If we continue building apps with SPAs included in the app like we're doing on some recent projects, we should also add something like

  config.before(:suite) do
    examples = RSpec.world.filtered_examples.values.flatten
    has_system_tests = examples.any? { |example| example.metadata[:type] == :system }
    if has_system_tests
      commands = [
        "rm -rf public/build",
        "rm -rf public/index.html",
        "cd frontend",
        "yarn install",
        "yarn build",
        "cd ..",
        "mv frontend/build public/build",
        "mv public/build/index.html public/index.html"
      ]
      command = commands.join(" && ")
      system(command)
      exitstatus = $CHILD_STATUS.exitstatus
      exit exitstatus if exitstatus.nonzero?
    end
  end

With these changes, we can also remove a few things from travis.yml (sudo apt-get update, sudo apt-get install chromium-chromedriver, export PATH=$PATH:/usr/lib/chromium-browser/, export DISPLAY=:99.0, sh -e /etc/init.d/xvfb start, and sleep 3)