Sha256: 4d0b22f3af20250ee24ada2836686a39c0db68e2a304851e38da753a14f58c9d

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

require "capybara/rails"

module ActionDispatch
  class IntegrationTest
    include Capybara::DSL

    setup do
      Capybara.reset_sessions!
      Capybara.use_default_driver
    end

    def self.use_javascript!(raise_on_javascript_errors: true) # rubocop:disable Metrics/MethodLength
      setup do
        Capybara.current_driver = Capybara.javascript_driver
      end

      teardown do
        next if failures.any?
        next unless raise_on_javascript_errors

        errors = page.driver.browser.manage.logs.get(:browser).select do |log|
          log.level == "SEVERE"
        end

        next unless errors.any?

        messages = errors
                   .map(&:message)
                   .map {|message| message[/(\d+:\d+ .*?)$/, 1] }
                   .join("\n")

        raise "JavaScript Errors\n#{messages}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minitest-utils-0.4.6 lib/minitest/utils/rails/capybara.rb
minitest-utils-0.4.5 lib/minitest/utils/rails/capybara.rb