2018-09-03 06:08:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
shared_examples 'a QA scenario class' do
|
|
|
|
let(:attributes) { spy('Runtime::Scenario') }
|
|
|
|
let(:runner) { spy('Specs::Runner') }
|
2019-03-27 15:03:03 -04:00
|
|
|
let(:release) { spy('Runtime::Release') }
|
|
|
|
let(:feature) { spy('Runtime::Feature') }
|
2018-09-03 06:08:49 -04:00
|
|
|
|
2019-03-27 15:03:03 -04:00
|
|
|
let(:args) { { gitlab_address: 'http://gitlab_address' } }
|
|
|
|
let(:named_options) { %w[--address http://gitlab_address] }
|
2018-09-03 06:08:49 -04:00
|
|
|
let(:tags) { [] }
|
|
|
|
let(:options) { %w[path1 path2] }
|
|
|
|
|
|
|
|
before do
|
2019-03-27 15:03:03 -04:00
|
|
|
stub_const('QA::Specs::Runner', runner)
|
2018-09-03 06:08:49 -04:00
|
|
|
stub_const('QA::Runtime::Release', release)
|
|
|
|
stub_const('QA::Runtime::Scenario', attributes)
|
2019-03-27 15:03:03 -04:00
|
|
|
stub_const('QA::Runtime::Feature', feature)
|
2018-09-03 06:08:49 -04:00
|
|
|
|
|
|
|
allow(runner).to receive(:perform).and_yield(runner)
|
2019-03-27 15:03:03 -04:00
|
|
|
allow(QA::Runtime::Address).to receive(:valid?).and_return(true)
|
2018-09-03 06:08:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds to perform' do
|
|
|
|
expect(subject).to respond_to(:perform)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets an address of the subject' do
|
2019-03-27 15:03:03 -04:00
|
|
|
subject.perform(args)
|
2018-09-03 06:08:49 -04:00
|
|
|
|
2019-03-27 15:03:03 -04:00
|
|
|
expect(attributes).to have_received(:define).with(:gitlab_address, 'http://gitlab_address').at_least(:once)
|
2018-09-03 06:08:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'performs before hooks' do
|
2019-03-27 15:03:03 -04:00
|
|
|
subject.perform(args)
|
2018-09-03 06:08:49 -04:00
|
|
|
|
|
|
|
expect(release).to have_received(:perform_before_hooks)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets tags on runner' do
|
2019-03-27 15:03:03 -04:00
|
|
|
subject.perform(args)
|
2018-09-03 06:08:49 -04:00
|
|
|
|
|
|
|
expect(runner).to have_received(:tags=).with(tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'specifying RSpec options' do
|
|
|
|
it 'sets options on runner' do
|
2019-03-27 15:03:03 -04:00
|
|
|
subject.perform(args, *options)
|
2018-09-03 06:08:49 -04:00
|
|
|
|
|
|
|
expect(runner).to have_received(:options=).with(options)
|
|
|
|
end
|
|
|
|
end
|
2019-03-27 15:03:03 -04:00
|
|
|
|
|
|
|
context 'with named command-line options' do
|
|
|
|
it 'converts options to attributes' do
|
|
|
|
described_class.launch!(named_options)
|
|
|
|
|
|
|
|
args do |k, v|
|
|
|
|
expect(attributes).to have_received(:define).with(k, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error if the option is invalid' do
|
|
|
|
expect { described_class.launch!(['--foo']) }.to raise_error(OptionParser::InvalidOption)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes on options after --' do
|
|
|
|
expect(described_class).to receive(:perform).with(attributes, *%w[--tag quarantine])
|
|
|
|
|
|
|
|
described_class.launch!(named_options.push(*%w[-- --tag quarantine]))
|
|
|
|
end
|
|
|
|
end
|
2018-09-03 06:08:49 -04:00
|
|
|
end
|