debian-mirror-gitlab/qa/spec/scenario_shared_examples.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2021-01-29 00:20:46 +05:30
module QA
RSpec.shared_examples 'a QA scenario class' do
2022-07-16 23:28:13 +05:30
let(:scenario) { class_spy('Runtime::Scenario') }
2022-06-21 17:19:12 +05:30
let(:runner) { class_spy('Specs::Runner') }
let(:release) { class_spy('Runtime::Release') }
let(:feature) { class_spy('Runtime::Feature') }
2021-01-29 00:20:46 +05:30
let(:args) { { gitlab_address: 'http://gitlab_address' } }
let(:named_options) { %w[--address http://gitlab_address] }
let(:tags) { [] }
let(:options) { %w[path1 path2] }
before do
stub_const('QA::Specs::Runner', runner)
stub_const('QA::Runtime::Release', release)
2022-07-16 23:28:13 +05:30
stub_const('QA::Runtime::Scenario', scenario)
2021-01-29 00:20:46 +05:30
stub_const('QA::Runtime::Feature', feature)
2022-07-16 23:28:13 +05:30
allow(QA::Runtime::Browser).to receive(:configure!)
allow(scenario).to receive(:attributes).and_return(args)
2021-01-29 00:20:46 +05:30
allow(runner).to receive(:perform).and_yield(runner)
end
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
it 'responds to perform' do
expect(subject).to respond_to(:perform)
end
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
it 'performs before hooks only once' do
subject.perform(args)
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
expect(release).to have_received(:perform_before_hooks).once
end
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
it 'sets tags on runner' do
subject.perform(args)
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
expect(runner).to have_received(:tags=).with(tags)
end
2019-07-07 11:18:12 +05:30
2022-06-21 17:19:12 +05:30
context 'with RSpec options' do
2021-01-29 00:20:46 +05:30
it 'sets options on runner' do
subject.perform(args, *options)
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
expect(runner).to have_received(:options=).with(options)
end
2019-07-07 11:18:12 +05:30
end
2021-01-29 00:20:46 +05:30
context 'with named command-line options' do
it 'converts options to attributes' do
described_class.launch!(named_options)
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
args do |k, v|
2022-07-16 23:28:13 +05:30
expect(scenario).to have_received(:define).with(k, v)
2021-01-29 00:20:46 +05:30
end
2019-07-07 11:18:12 +05:30
end
2021-01-29 00:20:46 +05:30
it 'raises an error if the option is invalid' do
expect { described_class.launch!(['--foo']) }.to raise_error(OptionParser::InvalidOption)
end
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
it 'passes on options after --' do
2022-07-16 23:28:13 +05:30
expect(described_class).to receive(:perform).with(args, *%w[--tag quarantine])
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
described_class.launch!(named_options.push(*%w[-- --tag quarantine]))
end
2019-07-07 11:18:12 +05:30
end
end
end