Skip to content
Snippets Groups Projects
Commit 23030439 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Rename class that loads CI configuration to Loader

parent d2b708ac
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -18,7 +18,7 @@ module Ci
initial_parsing
 
validate!
rescue Gitlab::Ci::Config::ParserError => e
rescue Gitlab::Ci::Config::LoaderError => e
raise ValidationError, e.message
end
 
Loading
Loading
module Gitlab
module Ci
class Config
class ParserError < StandardError; end
class LoaderError < StandardError; end
 
def initialize(config)
parser = Parser.new(config)
loader = Loader.new(config)
 
unless parser.valid?
raise ParserError, 'Invalid configuration format!'
unless loader.valid?
raise LoaderError, 'Invalid configuration format!'
end
 
@config = parser.parse
@config = loader.load
end
 
def to_hash
Loading
Loading
module Gitlab
module Ci
class Config
class Parser
class Loader
class FormatError < StandardError; end
 
def initialize(config)
Loading
Loading
@@ -12,7 +12,7 @@ module Gitlab
@config.is_a?(Hash)
end
 
def parse
def load
unless valid?
raise FormatError, 'Invalid configuration format'
end
Loading
Loading
require 'spec_helper'
 
describe Gitlab::Ci::Config::Parser do
let(:parser) { described_class.new(yml) }
describe Gitlab::Ci::Config::Loader do
let(:loader) { described_class.new(yml) }
 
context 'when yaml syntax is correct' do
let(:yml) { 'image: ruby:2.2' }
 
describe '#valid?' do
it 'returns true' do
expect(parser.valid?).to be true
expect(loader.valid?).to be true
end
end
 
describe '#parse' do
it 'returns a hash' do
expect(parser.parse).to be_a Hash
end
describe '#load' 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
Loading
Loading
@@ -28,14 +24,14 @@ describe Gitlab::Ci::Config::Parser do
 
describe '#valid?' do
it 'returns false' do
expect(parser.valid?).to be false
expect(loader.valid?).to be false
end
end
 
describe '#parse' do
describe '#load' do
it 'raises error' do
expect { parser.parse }.to raise_error(
Gitlab::Ci::Config::Parser::FormatError,
expect { loader.load }.to raise_error(
Gitlab::Ci::Config::Loader::FormatError,
'Invalid configuration format'
)
end
Loading
Loading
@@ -47,7 +43,7 @@ describe Gitlab::Ci::Config::Parser do
 
describe '#valid?' do
it 'returns false' do
expect(parser.valid?).to be false
expect(loader.valid?).to be false
end
end
end
Loading
Loading
Loading
Loading
@@ -37,7 +37,7 @@ describe Gitlab::Ci::Config do
describe '.new' do
it 'raises error' do
expect { config }.to raise_error(
Gitlab::Ci::Config::ParserError, /Invalid configuration format/
Gitlab::Ci::Config::LoaderError, /Invalid configuration format/
)
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment