Commit f0287186 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Raise exception when initializing unknown policy

parent 00e58f83
...@@ -4,11 +4,7 @@ module Gitlab ...@@ -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 ...@@ -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
......
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