2019-04-11 08:02:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-20 06:45:04 -05:00
|
|
|
require_relative '../qa'
|
2021-08-25 11:11:14 -04:00
|
|
|
|
2021-08-09 08:10:09 -04:00
|
|
|
require_relative 'qa_deprecation_toolkit_env'
|
|
|
|
QaDeprecationToolkitEnv.configure!
|
|
|
|
|
2021-12-28 16:16:11 -05:00
|
|
|
Knapsack::Adapters::RSpecAdapter.bind if QA::Runtime::Env.knapsack?
|
2019-06-03 06:37:43 -04:00
|
|
|
|
2022-01-07 13:16:06 -05:00
|
|
|
QA::Runtime::Browser.configure! unless QA::Runtime::Env.dry_run
|
2021-05-26 17:10:49 -04:00
|
|
|
QA::Runtime::AllureReport.configure!
|
|
|
|
QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes)
|
2019-07-09 11:40:46 -04:00
|
|
|
|
2020-09-02 11:10:54 -04:00
|
|
|
Dir[::File.join(__dir__, "support/shared_examples/*.rb")].sort.each { |f| require f }
|
2021-09-21 20:09:28 -04:00
|
|
|
Dir[::File.join(__dir__, "support/shared_contexts/*.rb")].sort.each { |f| require f }
|
2018-01-23 05:23:23 -05:00
|
|
|
|
2017-02-20 06:45:04 -05:00
|
|
|
RSpec.configure do |config|
|
2021-08-25 11:11:14 -04:00
|
|
|
config.include QA::Support::Matchers::EventuallyMatcher
|
|
|
|
config.include QA::Support::Matchers::HaveMatcher
|
2020-11-12 22:09:15 -05:00
|
|
|
|
2021-09-07 08:11:26 -04:00
|
|
|
config.add_formatter QA::Support::Formatters::ContextFormatter
|
|
|
|
config.add_formatter QA::Support::Formatters::QuarantineFormatter
|
2022-04-04 02:09:18 -04:00
|
|
|
config.add_formatter QA::Support::Formatters::FeatureFlagFormatter
|
2021-09-07 08:11:26 -04:00
|
|
|
config.add_formatter QA::Support::Formatters::TestStatsFormatter if QA::Runtime::Env.export_metrics?
|
2018-12-28 07:15:32 -05:00
|
|
|
|
2022-02-15 22:18:24 -05:00
|
|
|
config.before(:suite) do |suite|
|
|
|
|
QA::Resource::ReusableCollection.register_resource_classes do |collection|
|
|
|
|
QA::Resource::ReusableProject.register(collection)
|
|
|
|
QA::Resource::ReusableGroup.register(collection)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-18 20:10:29 -04:00
|
|
|
config.prepend_before do |example|
|
2022-02-24 19:17:32 -05:00
|
|
|
QA::Runtime::Logger.info("Starting test: #{Rainbow(example.full_description).bright}")
|
2022-02-15 22:18:24 -05:00
|
|
|
QA::Runtime::Example.current = example
|
2021-10-18 20:10:29 -04:00
|
|
|
|
|
|
|
# Reset fabrication counters tracked in resource base
|
|
|
|
Thread.current[:api_fabrication] = 0
|
|
|
|
Thread.current[:browser_ui_fabrication] = 0
|
2018-10-02 14:31:39 -04:00
|
|
|
end
|
|
|
|
|
2021-01-06 16:10:18 -05:00
|
|
|
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
|
|
|
|
|
2021-10-18 20:10:29 -04:00
|
|
|
# Add fabrication time to spec metadata
|
|
|
|
config.append_after do |example|
|
|
|
|
example.metadata[:api_fabrication] = Thread.current[:api_fabrication]
|
|
|
|
example.metadata[:browser_ui_fabrication] = Thread.current[:browser_ui_fabrication]
|
|
|
|
end
|
|
|
|
|
2019-10-31 05:06:29 -04:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2021-11-24 01:12:53 -05:00
|
|
|
config.after(:suite) do |suite|
|
2022-01-17 16:15:21 -05:00
|
|
|
# Write all test created resources to JSON file
|
2022-03-11 07:07:56 -05:00
|
|
|
QA::Tools::TestResourceDataProcessor.write_to_file(suite.reporter.failed_examples.any?)
|
2022-02-15 22:18:24 -05:00
|
|
|
|
|
|
|
# If requested, confirm that resources were used appropriately (e.g., not left with changes that interfere with
|
|
|
|
# further reuse)
|
|
|
|
QA::Resource::ReusableCollection.validate_resource_reuse if QA::Runtime::Env.validate_resource_reuse?
|
|
|
|
|
|
|
|
# If any tests failed, leave the resources behind to help troubleshoot, otherwise remove them.
|
2022-03-06 22:18:52 -05:00
|
|
|
# Do not remove the shared resource on live environments
|
2022-04-03 23:08:37 -04:00
|
|
|
begin
|
2022-04-07 14:08:29 -04:00
|
|
|
next if suite.reporter.failed_examples.present?
|
|
|
|
next unless QA::Runtime::Scenario.attributes.include?(:gitlab_address)
|
|
|
|
next if QA::Runtime::Env.running_on_dot_com?
|
|
|
|
|
|
|
|
QA::Resource::ReusableCollection.remove_all_via_api!
|
2022-04-03 23:08:37 -04:00
|
|
|
rescue QA::Resource::Errors::InternalServerError => e
|
|
|
|
# Temporarily prevent this error from failing jobs while the cause is investigated
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/issues/354387
|
|
|
|
QA::Runtime::Logger.debug(e.message)
|
|
|
|
end
|
2021-11-24 01:12:53 -05:00
|
|
|
end
|
|
|
|
|
2022-01-10 04:13:43 -05:00
|
|
|
config.append_after(:suite) do
|
|
|
|
QA::Tools::KnapsackReport.move_regenerated_report if QA::Runtime::Env.knapsack?
|
|
|
|
end
|
|
|
|
|
2017-02-20 06:45:04 -05:00
|
|
|
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-02-19 07:12:07 -05:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2022-03-21 05:08:30 -04:00
|
|
|
# This option allows to use shorthand aliases for adding :focus metadata - fit, fdescribe and fcontext
|
|
|
|
config.filter_run_when_matching :focus
|
|
|
|
|
2019-12-03 04:09:09 -05:00
|
|
|
if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
|
2020-04-02 20:07:49 -04:00
|
|
|
non_quarantine_retries = QA::Runtime::Env.ci_project_name =~ /staging|canary|production/ ? 3 : 2
|
2019-05-06 22:49:39 -04:00
|
|
|
config.around do |example|
|
2022-01-19 04:14:10 -05:00
|
|
|
quarantine = example.metadata[:quarantine]
|
|
|
|
different_quarantine_context = QA::Specs::Helpers::Quarantine.quarantined_different_context?(quarantine)
|
|
|
|
focused_quarantine = QA::Specs::Helpers::Quarantine.filters.key?(:quarantine)
|
|
|
|
|
|
|
|
# Do not disable retry when spec is quarantined but on different environment
|
|
|
|
next example.run_with_retry(retry: non_quarantine_retries) if different_quarantine_context && !focused_quarantine
|
|
|
|
|
|
|
|
example.run_with_retry(retry: quarantine ? 1 : non_quarantine_retries)
|
2019-05-06 22:49:39 -04:00
|
|
|
end
|
2019-02-19 07:12:07 -05:00
|
|
|
end
|
2017-02-20 06:45:04 -05:00
|
|
|
end
|