Raise exception when initializing unknown policy

This commit is contained in:
Grzegorz Bizon 2017-09-18 14:39:09 +02:00
parent 00e58f835a
commit f028718641
2 changed files with 3 additions and 10 deletions

View file

@ -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

View file

@ -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