Raise exception when initializing unknown policy
This commit is contained in:
parent
00e58f835a
commit
f028718641
2 changed files with 3 additions and 10 deletions
|
@ -4,11 +4,7 @@ module Gitlab
|
||||||
module Policy
|
module Policy
|
||||||
def self.fabricate(specs)
|
def self.fabricate(specs)
|
||||||
specifications = specs.to_h.map do |spec, value|
|
specifications = specs.to_h.map do |spec, value|
|
||||||
begin
|
self.const_get(spec.to_s.camelize).new(value)
|
||||||
self.const_get(spec.to_s.camelize).new(value)
|
|
||||||
rescue NameError
|
|
||||||
next
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
specifications.compact
|
specifications.compact
|
||||||
|
|
|
@ -20,11 +20,8 @@ describe Gitlab::Ci::Build::Policy do
|
||||||
|
|
||||||
context 'when some policies are not defined' do
|
context 'when some policies are not defined' do
|
||||||
it 'gracefully skips unknown policies' do
|
it 'gracefully skips unknown policies' do
|
||||||
specs = described_class.fabricate(something: 'first', else: 'unknown')
|
expect { described_class.fabricate(unknown: 'first') }
|
||||||
|
.to raise_error(NameError)
|
||||||
expect(specs).to be_an Array
|
|
||||||
expect(specs).to be_one
|
|
||||||
expect(policy).to have_received(:new).with('first')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue