Commit f0287186 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Raise exception when initializing unknown policy

parent 00e58f83
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment