diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2019-03-11 11:50:09 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-03-11 11:50:09 +0000 |
commit | c6a6b8a24e0e761dc44d8439740e92679afc10d7 (patch) | |
tree | dfaf7eaca77c34f592677b072760a7e61adaa6a2 /qa/spec/spec_helper.rb | |
parent | a89df58527aae693438001ab0800363e7a7d6b07 (diff) | |
download | gitlab-ce-c6a6b8a24e0e761dc44d8439740e92679afc10d7.tar.gz |
Skip contexts in quarantine
This avoids running before/after blocks for tests that are in quarantine
Diffstat (limited to 'qa/spec/spec_helper.rb')
-rw-r--r-- | qa/spec/spec_helper.rb | 47 |
1 files changed, 1 insertions, 46 deletions
diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb index cbdd6e881b1..be13c3fb683 100644 --- a/qa/spec/spec_helper.rb +++ b/qa/spec/spec_helper.rb @@ -6,16 +6,10 @@ require 'rspec/retry' end RSpec.configure do |config| - config.before(:context) do - if self.class.metadata.keys.include?(:quarantine) - skip_or_run_quarantined_tests(self.class.metadata.keys, config.inclusion_filter.rules.keys) - end - end + QA::Specs::Helpers::Quarantine.configure_rspec config.before do |example| QA::Runtime::Logger.debug("Starting test: #{example.full_description}") if QA::Runtime::Env.debug? - - skip_or_run_quarantined_tests(example.metadata.keys, config.inclusion_filter.rules.keys) end config.expect_with :rspec do |expectations| @@ -44,42 +38,3 @@ RSpec.configure do |config| example.run_with_retry retry: retry_times end end - -# Skip tests in quarantine unless we explicitly focus on them. -# Skip the entire context if a context is tagged. This avoids running before -# blocks unnecessarily. -# If quarantine is focussed, skip tests/contexts that have other metadata -# unless they're also focussed. This lets us run quarantined tests in a -# particular category without running tests in other categories. -# E.g., if a test is tagged 'smoke' and 'quarantine', and another is tagged -# 'ldap' and 'quarantine', if we wanted to run just quarantined smoke tests -# using `--tag quarantine --tag smoke`, without this check we'd end up -# running that ldap test as well. -# We could use an exclusion filter, but this way the test report will list -# the quarantined tests when they're not run so that we're aware of them -def skip_or_run_quarantined_tests(metadata_keys, filter_keys) - included_filters = filters_other_than_quarantine(filter_keys) - - if filter_keys.include?(:quarantine) - skip("Only running tests tagged with :quarantine and any of #{included_filters}") unless quarantine_and_optional_other_tag?(metadata_keys, included_filters) - else - skip('In quarantine') if metadata_keys.include?(:quarantine) - end -end - -def filters_other_than_quarantine(filter_keys) - filter_keys.reject { |key| key == :quarantine } -end - -# Checks if a test has the 'quarantine' tag and other tags in the inclusion filter. -# -# Returns true if -# - the metadata includes the quarantine tag -# - and the metadata and inclusion filter both have any other tag -# - or no other tags are in the inclusion filter -def quarantine_and_optional_other_tag?(metadata_keys, included_filters) - return false unless metadata_keys.include? :quarantine - return true if included_filters.empty? - - included_filters.any? { |key| metadata_keys.include? key } -end |