diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index 27ba915961d..5bebb5ccec0 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -5,13 +5,17 @@ module QA # set to 'false' to have Chrome run visibly instead of headless def chrome_headless? - (ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i) != 0 + enabled?(ENV['CHROME_HEADLESS']) end def running_in_ci? ENV['CI'] || ENV['CI_SERVER'] end + def signup_disabled? + enabled?(ENV['SIGNUP_DISABLED'], default: false) + end + # specifies token that can be used for the api def personal_access_token ENV['PERSONAL_ACCESS_TOKEN'] @@ -83,6 +87,14 @@ module QA raise ArgumentError, "Please provide GITHUB_ACCESS_TOKEN" end + + private + + def enabled?(value, default: true) + return default if value.nil? + + (value =~ /^(false|no|0)$/i) != 0 + end end end end diff --git a/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb b/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb index 478a5cb9c4c..bc1c2abdf56 100644 --- a/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb +++ b/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb @@ -16,13 +16,13 @@ module QA end end - context :manage do + context :manage, :skip_signup_disabled do describe 'standard' do it_behaves_like 'registration and login' end end - context :manage, :orchestrated, :ldap do + context :manage, :orchestrated, :ldap, :skip_signup_disabled do describe 'while LDAP is enabled' do it_behaves_like 'registration and login' end diff --git a/qa/qa/specs/runner.rb b/qa/qa/specs/runner.rb index fea0ef94df3..ad397c13f0c 100644 --- a/qa/qa/specs/runner.rb +++ b/qa/qa/specs/runner.rb @@ -23,6 +23,8 @@ module QA args.push(%w[--tag ~orchestrated]) unless (%w[-t --tag] & options).any? end + args.push(%w[--tag ~skip_signup_disabled]) if QA::Runtime::Env.signup_disabled? + args.push(options) args.push(DEFAULT_TEST_PATH_ARGS) unless options.any? { |opt| opt =~ %r{/features/} } diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index d889d185a45..fda955f6600 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -1,39 +1,47 @@ describe QA::Runtime::Env do include Support::StubENV - describe '.chrome_headless?' do + shared_examples 'boolean method' do |method, env_key, default| context 'when there is an env variable set' do it 'returns false when falsey values specified' do - stub_env('CHROME_HEADLESS', 'false') - expect(described_class.chrome_headless?).to be_falsey + stub_env(env_key, 'false') + expect(described_class.public_send(method)).to be_falsey - stub_env('CHROME_HEADLESS', 'no') - expect(described_class.chrome_headless?).to be_falsey + stub_env(env_key, 'no') + expect(described_class.public_send(method)).to be_falsey - stub_env('CHROME_HEADLESS', '0') - expect(described_class.chrome_headless?).to be_falsey + stub_env(env_key, '0') + expect(described_class.public_send(method)).to be_falsey end it 'returns true when anything else specified' do - stub_env('CHROME_HEADLESS', 'true') - expect(described_class.chrome_headless?).to be_truthy + stub_env(env_key, 'true') + expect(described_class.public_send(method)).to be_truthy - stub_env('CHROME_HEADLESS', '1') - expect(described_class.chrome_headless?).to be_truthy + stub_env(env_key, '1') + expect(described_class.public_send(method)).to be_truthy - stub_env('CHROME_HEADLESS', 'anything') - expect(described_class.chrome_headless?).to be_truthy + stub_env(env_key, 'anything') + expect(described_class.public_send(method)).to be_truthy end end context 'when there is no env variable set' do - it 'returns the default, true' do - stub_env('CHROME_HEADLESS', nil) - expect(described_class.chrome_headless?).to be_truthy + it "returns the default, #{default}" do + stub_env(env_key, nil) + expect(described_class.public_send(method)).to be(default) end end end + describe '.signup_disabled?' do + it_behaves_like 'boolean method', :signup_disabled?, 'SIGNUP_DISABLED', false + end + + describe '.chrome_headless?' do + it_behaves_like 'boolean method', :chrome_headless?, 'CHROME_HEADLESS', true + end + describe '.running_in_ci?' do context 'when there is an env variable set' do it 'returns true if CI' do diff --git a/qa/spec/specs/runner_spec.rb b/qa/spec/specs/runner_spec.rb index cf22d1c9395..9ddaf7ab1b3 100644 --- a/qa/spec/specs/runner_spec.rb +++ b/qa/spec/specs/runner_spec.rb @@ -62,6 +62,20 @@ describe QA::Specs::Runner do end end + context 'when SIGNUP_DISABLED is true' do + before do + allow(QA::Runtime::Env).to receive(:signup_disabled?).and_return(true) + end + + subject { described_class.new } + + it 'it includes default args and excludes the skip_signup_disabled tag' do + expect_rspec_runner_arguments(['--tag', '~orchestrated', '--tag', '~skip_signup_disabled', *described_class::DEFAULT_TEST_PATH_ARGS]) + + subject.perform + end + end + def expect_rspec_runner_arguments(arguments) expect(RSpec::Core::Runner).to receive(:run) .with(arguments, $stderr, $stdout)