diff --git a/ee/spec/models/factories_spec.rb b/ee/spec/models/factories_spec.rb index 09a96575f779f9ec30fc5525b645b4bdac577cad..330ddcc0c703bd3a9b8d1f13772f647b1a0ef741 100644 --- a/ee/spec/models/factories_spec.rb +++ b/ee/spec/models/factories_spec.rb @@ -82,6 +82,7 @@ ].freeze geo_configured = Gitlab.ee? && Gitlab::Geo.geo_database_configured? + check_create = !Support::GitlabCi.predictive_job? && !Support::GitlabCi.fail_fast_job? shared_examples 'factory' do |factory| skip_any = skipped.include?([factory.name, any]) @@ -107,7 +108,7 @@ expect { build(factory.name) }.not_to raise_error end - it 'does not raise error when created' do + it 'does not raise error when created', if: check_create do pending 'Factory skipped linting due to legacy error' if skip_any expect { create(factory.name) }.not_to raise_error # rubocop:disable Rails/SaveBang @@ -117,7 +118,7 @@ skip_trait = skip_any || skipped.include?([factory.name, trait_name.to_sym]) describe "linting :#{trait_name} trait" do - it 'does not raise error when created' do + it 'does not raise error when created', if: check_create do skip 'Trait skipped linting due to legacy error' if skip_trait expect { create(factory.name, trait_name) }.not_to raise_error diff --git a/spec/support/helpers/gitlab_ci.rb b/spec/support/helpers/gitlab_ci.rb new file mode 100644 index 0000000000000000000000000000000000000000..493f81f6b5be2a7c0c217b219b3ef9f73c67901b --- /dev/null +++ b/spec/support/helpers/gitlab_ci.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Support + module GitlabCi + module_function + + def predictive_job? + ENV['CI_JOB_NAME']&.include?('predictive') + end + + def fail_fast_job? + ENV['CI_JOB_NAME']&.include?('fail-fast') + end + end +end diff --git a/spec/support_specs/helpers/gitlab_ci_spec.rb b/spec/support_specs/helpers/gitlab_ci_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..afc8eceb067495811fa1a83a0e57e1250e11de0e --- /dev/null +++ b/spec/support_specs/helpers/gitlab_ci_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rspec-parameterized' + +require_relative '../../support/helpers/gitlab_ci' + +RSpec.describe Support::GitlabCi, feature_category: :tooling do # rubocop:disable RSpec/FilePath -- Avoid deep nesting + using RSpec::Parameterized::TableSyntax + + describe '.predictive_job?' do + before do + stub_env('CI_JOB_NAME', name) + end + + subject { described_class.predictive_job? } + + where(:name, :expected) do + 'rspec-ee unit predictive 4/4' | be_truthy + 'rspec system predictive 1/4' | be_truthy + 'rspec unit 1/4' | be_falsey + nil | be_falsey + end + + with_them do + it { is_expected.to expected } + end + end + + describe '.fail_fast_job?' do + before do + stub_env('CI_JOB_NAME', name) + end + + subject { described_class.fail_fast_job? } + + where(:name, :expected) do + 'rspec fail-fast' | be_truthy + 'rspec-ee fail-fast' | be_truthy + 'rspec-ee unit predictive 4/4' | be_falsey + nil | be_falsey + end + + with_them do + it { is_expected.to expected } + end + end +end