Commit 23030439 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Rename class that loads CI configuration to Loader

parent d2b708ac
...@@ -18,7 +18,7 @@ module Ci ...@@ -18,7 +18,7 @@ module Ci
initial_parsing initial_parsing
validate! validate!
rescue Gitlab::Ci::Config::ParserError => e rescue Gitlab::Ci::Config::LoaderError => e
raise ValidationError, e.message raise ValidationError, e.message
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
class ParserError < StandardError; end class LoaderError < StandardError; end
def initialize(config) def initialize(config)
parser = Parser.new(config) loader = Loader.new(config)
unless parser.valid? unless loader.valid?
raise ParserError, 'Invalid configuration format!' raise LoaderError, 'Invalid configuration format!'
end end
@config = parser.parse @config = loader.load
end end
def to_hash def to_hash
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
class Parser class Loader
class FormatError < StandardError; end class FormatError < StandardError; end
def initialize(config) def initialize(config)
...@@ -12,7 +12,7 @@ module Gitlab ...@@ -12,7 +12,7 @@ module Gitlab
@config.is_a?(Hash) @config.is_a?(Hash)
end end
def parse def load
unless valid? unless valid?
raise FormatError, 'Invalid configuration format' raise FormatError, 'Invalid configuration format'
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Parser do describe Gitlab::Ci::Config::Loader do
let(:parser) { described_class.new(yml) } let(:loader) { described_class.new(yml) }
context 'when yaml syntax is correct' do context 'when yaml syntax is correct' do
let(:yml) { 'image: ruby:2.2' } let(:yml) { 'image: ruby:2.2' }
describe '#valid?' do describe '#valid?' do
it 'returns true' do it 'returns true' do
expect(parser.valid?).to be true expect(loader.valid?).to be true
end end
end end
describe '#parse' do describe '#load' do
it 'returns a hash' do
expect(parser.parse).to be_a Hash
end
it 'returns a valid hash' do it 'returns a valid hash' do
expect(parser.parse).to eq(image: 'ruby:2.2') expect(loader.load).to eq(image: 'ruby:2.2')
end end
end end
end end
...@@ -28,14 +24,14 @@ describe Gitlab::Ci::Config::Parser do ...@@ -28,14 +24,14 @@ describe Gitlab::Ci::Config::Parser do
describe '#valid?' do describe '#valid?' do
it 'returns false' do it 'returns false' do
expect(parser.valid?).to be false expect(loader.valid?).to be false
end end
end end
describe '#parse' do describe '#load' do
it 'raises error' do it 'raises error' do
expect { parser.parse }.to raise_error( expect { loader.load }.to raise_error(
Gitlab::Ci::Config::Parser::FormatError, Gitlab::Ci::Config::Loader::FormatError,
'Invalid configuration format' 'Invalid configuration format'
) )
end end
...@@ -47,7 +43,7 @@ describe Gitlab::Ci::Config::Parser do ...@@ -47,7 +43,7 @@ describe Gitlab::Ci::Config::Parser do
describe '#valid?' do describe '#valid?' do
it 'returns false' do it 'returns false' do
expect(parser.valid?).to be false expect(loader.valid?).to be false
end end
end end
end end
......
...@@ -37,7 +37,7 @@ describe Gitlab::Ci::Config do ...@@ -37,7 +37,7 @@ describe Gitlab::Ci::Config do
describe '.new' do describe '.new' do
it 'raises error' do it 'raises error' do
expect { config }.to raise_error( expect { config }.to raise_error(
Gitlab::Ci::Config::ParserError, /Invalid configuration format/ Gitlab::Ci::Config::LoaderError, /Invalid configuration format/
) )
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