debian-mirror-gitlab/qa/spec/spec_helper.rb

85 lines
2.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require_relative '../qa'
2021-11-11 11:23:49 +05:30
require 'securerandom'
require 'pathname'
2021-06-08 01:23:25 +05:30
require 'active_support/core_ext/hash'
2021-09-04 01:27:46 +05:30
require 'active_support/core_ext/object/blank'
2017-08-17 22:00:37 +05:30
2021-10-27 15:23:28 +05:30
require_relative 'qa_deprecation_toolkit_env'
QaDeprecationToolkitEnv.configure!
2021-11-11 11:23:49 +05:30
Knapsack::Adapters::RSpecAdapter.bind if ENV['CI'] && QA::Runtime::Env.knapsack? && !ENV['NO_KNAPSACK']
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
QA::Runtime::Browser.configure!
2021-09-04 01:27:46 +05:30
QA::Runtime::AllureReport.configure!
QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes)
2019-09-30 21:07:59 +05:30
2020-11-24 15:15:51 +05:30
Dir[::File.join(__dir__, "support/shared_examples/*.rb")].sort.each { |f| require f }
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
RSpec.configure do |config|
2021-11-11 11:23:49 +05:30
config.include QA::Support::Matchers::EventuallyMatcher
config.include QA::Support::Matchers::HaveMatcher
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
config.add_formatter QA::Support::Formatters::ContextFormatter
config.add_formatter QA::Support::Formatters::QuarantineFormatter
config.add_formatter QA::Support::Formatters::TestStatsFormatter if QA::Runtime::Env.export_metrics?
2019-03-02 22:35:43 +05:30
2018-12-13 13:39:08 +05:30
config.before do |example|
2020-01-01 13:55:28 +05:30
QA::Runtime::Logger.debug("\nStarting test: #{example.full_description}\n")
2019-12-26 22:10:19 +05:30
end
2021-03-08 18:12:59 +05:30
config.after do
# If a .netrc file was created during the test, delete it so that subsequent tests don't try to use the same logins
QA::Git::Repository.new.delete_netrc
end
2019-12-26 22:10:19 +05:30
config.after(:context) do
if !QA::Runtime::Browser.blank_page? && QA::Page::Main::Menu.perform(&:signed_in?)
QA::Page::Main::Menu.perform(&:sign_out)
raise(
<<~ERROR
The test left the browser signed in.
Usually, Capybara prevents this from happening but some things can
interfere. For example, if it has an `after(:context)` block that logs
in, the browser will stay logged in and this will cause the next test
to fail.
Please make sure the test does not leave the browser signed in.
ERROR
)
end
2018-12-13 13:39:08 +05:30
end
2017-08-17 22:00:37 +05:30
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
2019-03-13 22:55:13 +05:30
# 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
2020-01-01 13:55:28 +05:30
if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
2020-04-22 19:07:51 +05:30
non_quarantine_retries = QA::Runtime::Env.ci_project_name =~ /staging|canary|production/ ? 3 : 2
2019-09-04 21:01:54 +05:30
config.around do |example|
2020-04-22 19:07:51 +05:30
retry_times = example.metadata.key?(:quarantine) ? 1 : non_quarantine_retries
2019-09-04 21:01:54 +05:30
example.run_with_retry retry: retry_times
end
2019-03-13 22:55:13 +05:30
end
2017-08-17 22:00:37 +05:30
end