summaryrefslogtreecommitdiff
path: root/qa/qa/specs/config.rb
blob: 78a93828d36b17c706befdc0f6ab90740eb6976d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'rspec/core'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
require 'selenium-webdriver'

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/LineLength

module QA
  module Specs
    class Config < Scenario::Template
      attr_writer :address

      def initialize
        @address = ENV['GITLAB_URL']
      end

      def perform
        raise 'Please configure GitLab address!' unless @address

        configure_rspec!
        configure_capybara!
      end

      def configure_rspec!
        RSpec.configure do |config|
          config.expect_with :rspec do |expectations|
            # This option will default to `true` in RSpec 4. It makes the `description`
            # and `failure_message` of custom matchers include text for helper methods
            # defined using `chain`.
            expectations.include_chain_clauses_in_custom_matcher_descriptions = true
          end

          config.mock_with :rspec do |mocks|
            # Prevents you from mocking or stubbing a method that does not exist on
            # a real object. This is generally recommended, and will default to
            # `true` in RSpec 4.
            mocks.verify_partial_doubles = true
          end

          # Run specs in random order to surface order dependencies.
          config.order = :random
          Kernel.srand config.seed

          # config.before(:all) do
          #   page.current_window.resize_to(1200, 1800)
          # end

          config.formatter = :documentation
          config.color = true
        end
      end

      def configure_capybara!
        Capybara.register_driver :chrome do |app|
          capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
            'chromeOptions' => {
              'binary' => '/opt/google/chrome-beta/google-chrome-beta',
              'args' => %w[headless no-sandbox disable-gpu]
            }
          )

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

        Capybara.configure do |config|
          config.app_host = @address
          config.default_driver = :chrome
          config.javascript_driver = :chrome
          config.default_max_wait_time = 4

          # https://github.com/mattheworiordan/capybara-screenshot/issues/164
          config.save_path = 'tmp'
        end
      end
    end
  end
end