2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'fast_spec_helper'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Build::Policy do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:policy) { spy('policy specification') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const("#{described_class}::Something", policy)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.fabricate' do
|
|
|
|
context 'when policy exists' do
|
|
|
|
it 'fabricates and initializes relevant policy' do
|
|
|
|
specs = described_class.fabricate(something: 'some value')
|
|
|
|
|
|
|
|
expect(specs).to be_an Array
|
|
|
|
expect(specs).to be_one
|
|
|
|
expect(policy).to have_received(:new).with('some value')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when some policies are not defined' do
|
|
|
|
it 'gracefully skips unknown policies' do
|
|
|
|
expect { described_class.fabricate(unknown: 'first') }
|
|
|
|
.to raise_error(NameError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing a nil value as specs' do
|
|
|
|
it 'returns an empty array' do
|
|
|
|
specs = described_class.fabricate(nil)
|
|
|
|
|
|
|
|
expect(specs).to be_an Array
|
|
|
|
expect(specs).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|