spec_helper.rb 1.5 KB
Newer Older
T
Thong Kuah 已提交
1 2
# frozen_string_literal: true

3
require_relative '../qa'
4
require 'rspec/retry'
5

6 7 8 9 10
if ENV['CI'] && QA::Runtime::Env.knapsack? && !ENV['NO_KNAPSACK']
  require 'knapsack'
  Knapsack::Adapters::RSpecAdapter.bind
end

11 12 13 14
QA::Runtime::Browser.configure!

QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes) if QA::Runtime::Env.runtime_scenario_attributes

M
Mark Lapierre 已提交
15 16 17
%w[helpers shared_examples].each do |d|
  Dir[::File.join(__dir__, d, '**', '*.rb')].each { |f| require f }
end
18

19
RSpec.configure do |config|
M
Mark Lapierre 已提交
20
  QA::Specs::Helpers::Quarantine.configure_rspec
21

M
Mark Lapierre 已提交
22 23
  config.before do |example|
    QA::Runtime::Logger.debug("Starting test: #{example.full_description}") if QA::Runtime::Env.debug?
M
Mark Lapierre 已提交
24 25
  end

26 27 28 29 30 31 32 33 34 35 36 37 38 39
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.shared_context_metadata_behavior = :apply_to_host_groups
  config.disable_monkey_patching!
  config.expose_dsl_globally = true
  config.profile_examples = 10
  config.order = :random
  Kernel.srand config.seed
40 41 42 43 44 45 46

  # show retry status in spec process
  config.verbose_retry = true

  # show exception that triggers a retry if verbose_retry is set to true
  config.display_try_failure_messages = true

47 48 49 50 51
  if ENV['CI']
    config.around do |example|
      retry_times = example.metadata.keys.include?(:quarantine) ? 1 : 2
      example.run_with_retry retry: retry_times
    end
52
  end
53
end