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
|
||||
def self.fabricate(specs)
|
||||
specifications = specs.to_h.map do |spec, value|
|
||||
begin
|
||||
self.const_get(spec.to_s.camelize).new(value)
|
||||
rescue NameError
|
||||
next
|
||||
end
|
||||
self.const_get(spec.to_s.camelize).new(value)
|
||||
end
|
||||
|
||||
specifications.compact
|
||||
|
|
|
@ -20,11 +20,8 @@ describe Gitlab::Ci::Build::Policy do
|
|||
|
||||
context 'when some policies are not defined' do
|
||||
it 'gracefully skips unknown policies' do
|
||||
specs = described_class.fabricate(something: 'first', else: 'unknown')
|
||||
|
||||
expect(specs).to be_an Array
|
||||
expect(specs).to be_one
|
||||
expect(policy).to have_received(:new).with('first')
|
||||
expect { described_class.fabricate(unknown: 'first') }
|
||||
.to raise_error(NameError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue