2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-15 06:20:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Gitlab::Ci::Build::Policy do
|
2017-09-15 06:20:53 -04:00
|
|
|
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
|
2017-09-18 08:39:09 -04:00
|
|
|
expect { described_class.fabricate(unknown: 'first') }
|
|
|
|
.to raise_error(NameError)
|
2017-09-15 06:20:53 -04:00
|
|
|
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
|