Sha256: 7ccfbec00d2255975aa80bc52ee02fd6d6d9190cda21d8ad98ae08cb35712755

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require "capybara/poltergeist"
require "capybara-screenshot/rspec"

module Decidim
  # Helpers meant to be used only during capybara test runs.
  module CapybaraTestHelpers
    def switch_to_host(host = "lvh.me")
      unless /lvh\.me$/.match?(host)
        raise "Can't switch to a custom host unless it really exists. Use `whatever.lvh.me` as a workaround."
      end

      app_host = (host ? "http://#{host}" : nil)
      Capybara.app_host = app_host
    end

    def switch_to_default_host
      Capybara.app_host = nil
    end
  end
end

capybara_options = {
  extensions: [
    File.expand_path(
      File.join(__dir__, "phantomjs_polyfills", "promise.js")
    ),
    File.expand_path(
      File.join(__dir__, "phantomjs_polyfills", "phantomjs-shim.js")
    )
  ],
  js_errors: true,
  url_whitelist: ["http://*.lvh.me", "localhost", "127.0.0.1"],
  timeout: 1.minute
}

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, capybara_options)
end

Capybara.register_driver :debug do |app|
  Capybara::Poltergeist::Driver.new(app, capybara_options.merge(inspector: true))
end

Capybara::Screenshot.prune_strategy = :keep_last_run
Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = true

Capybara.configure do |config|
  config.always_include_port = true
  config.default_driver = :poltergeist
end

RSpec.configure do |config|
  config.before :each, type: :feature do
    Capybara.current_session.driver.reset!
    switch_to_default_host
  end

  config.include Decidim::CapybaraTestHelpers, type: :feature

  if ENV["CI"]
    require "rspec/repeat"

    config.include RSpec::Repeat
    config.around :each, type: :feature do |example|
      repeat example, 5.times, wait: 1, verbose: true
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
decidim-dev-0.3.2 lib/decidim/dev/test/rspec_support/capybara.rb
decidim-0.3.2 decidim-dev/lib/decidim/dev/test/rspec_support/capybara.rb
decidim-dev-0.3.1 lib/decidim/dev/test/rspec_support/capybara.rb
decidim-0.3.1 decidim-dev/lib/decidim/dev/test/rspec_support/capybara.rb
decidim-dev-0.3.0 lib/decidim/dev/test/rspec_support/capybara.rb
decidim-0.3.0 decidim-dev/lib/decidim/dev/test/rspec_support/capybara.rb