2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
RSpec.describe QA::Scenario::Template do
|
2022-07-16 23:28:13 +05:30
|
|
|
let(:release) { spy('QA::Runtime::Release') } # rubocop:disable RSpec/VerifiedDoubles
|
|
|
|
let(:feature) { class_spy('QA::Runtime::Feature') }
|
|
|
|
let(:scenario) { class_spy('QA::Runtime::Scenario') }
|
|
|
|
let(:runner) { class_spy('QA::Specs::Runner') }
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:gitlab_address) { 'https://gitlab.com/' }
|
2022-07-16 23:28:13 +05:30
|
|
|
let(:gitlab_address_from_env) { 'https://staging.gitlab.com/' }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('QA::Runtime::Release', release)
|
|
|
|
stub_const('QA::Runtime::Feature', feature)
|
2022-07-16 23:28:13 +05:30
|
|
|
stub_const('QA::Runtime::Scenario', scenario)
|
|
|
|
stub_const('QA::Specs::Runner', runner)
|
|
|
|
|
|
|
|
allow(QA::Runtime::Env).to receive(:knapsack?).and_return(false)
|
|
|
|
allow(QA::Runtime::Env).to receive(:gitlab_url).and_return(gitlab_address_from_env)
|
|
|
|
|
|
|
|
allow(QA::Runtime::Browser).to receive(:configure!)
|
|
|
|
|
|
|
|
allow(scenario).to receive(:attributes).and_return({ gitlab_address: gitlab_address })
|
|
|
|
allow(scenario).to receive(:define)
|
|
|
|
|
|
|
|
QA::Support::GitlabAddress.instance_variable_set(:@initialized, false)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows a feature to be enabled' do
|
2021-06-08 01:23:25 +05:30
|
|
|
subject.perform({ gitlab_address: gitlab_address, enable_feature: 'a-feature' })
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(feature).to have_received(:enable).with('a-feature')
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(feature).to have_received(:disable).with('a-feature')
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it 'allows a feature to be disabled' do
|
2022-07-16 23:28:13 +05:30
|
|
|
allow(QA::Runtime::Feature).to receive(:enabled?).with('another-feature').and_return(true)
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' })
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(feature).to have_received(:disable).with('another-feature')
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(feature).to have_received(:enable).with('another-feature')
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not disable a feature if already disabled' do
|
2022-07-16 23:28:13 +05:30
|
|
|
allow(QA::Runtime::Feature).to receive(:enabled?).with('another-feature').and_return(false)
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' })
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(feature).not_to have_received(:disable).with('another-feature')
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'ensures an enabled feature is disabled afterwards' do
|
|
|
|
allow(QA::Specs::Runner).to receive(:perform).and_raise('failed test')
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect { subject.perform({ gitlab_address: gitlab_address, enable_feature: 'a-feature' }) }
|
|
|
|
.to raise_error('failed test')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(feature).to have_received(:enable).with('a-feature')
|
|
|
|
expect(feature).to have_received(:disable).with('a-feature')
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it 'ensures a disabled feature is enabled afterwards' do
|
|
|
|
allow(QA::Specs::Runner).to receive(:perform).and_raise('failed test')
|
2022-07-16 23:28:13 +05:30
|
|
|
allow(QA::Runtime::Feature).to receive(:enabled?).with('another-feature').and_return(true)
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect { subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' }) }
|
|
|
|
.to raise_error('failed test')
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(feature).to have_received(:disable).with('another-feature')
|
|
|
|
expect(feature).to have_received(:enable).with('another-feature')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensures a disabled feature is not enabled afterwards if it was disabled earlier' do
|
|
|
|
allow(QA::Specs::Runner).to receive(:perform).and_raise('failed test')
|
2022-07-16 23:28:13 +05:30
|
|
|
allow(QA::Runtime::Feature).to receive(:enabled?).with('another-feature').and_return(false)
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect { subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' }) }
|
|
|
|
.to raise_error('failed test')
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(feature).not_to have_received(:disable).with('another-feature')
|
|
|
|
expect(feature).not_to have_received(:enable).with('another-feature')
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it 'defines gitlab address from positional argument' do
|
|
|
|
allow(scenario).to receive(:attributes).and_return({})
|
|
|
|
|
|
|
|
subject.perform({}, gitlab_address)
|
|
|
|
|
|
|
|
expect(scenario).to have_received(:define).with(:gitlab_address, gitlab_address)
|
|
|
|
expect(scenario).to have_received(:define).with(:about_address, 'https://about.gitlab.com/')
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it "defaults to gitlab address from env" do
|
|
|
|
allow(scenario).to receive(:attributes).and_return({})
|
|
|
|
|
|
|
|
subject.perform({})
|
|
|
|
|
|
|
|
expect(scenario).to have_received(:define).with(:gitlab_address, gitlab_address_from_env)
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it 'defines klass attribute' do
|
|
|
|
subject.perform({ gitlab_address: gitlab_address })
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(scenario).to have_received(:define).with(:klass, 'QA::Scenario::Template')
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|