2016-06-16 23:09:34 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Config::Node::Configurable do
|
|
|
|
let(:node) { Class.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
node.include(described_class)
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe 'validations' do
|
|
|
|
let(:validator) { node.validator.new(instance) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
node.class_eval do
|
|
|
|
attr_reader :config
|
|
|
|
|
|
|
|
def initialize(config)
|
|
|
|
@config = config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
validator.validate
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when node validator is invalid' do
|
|
|
|
let(:instance) { node.new('ls') }
|
|
|
|
|
|
|
|
it 'returns invalid validator' do
|
|
|
|
expect(validator).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when node instance is valid' do
|
|
|
|
let(:instance) { node.new(key: 'value') }
|
|
|
|
|
|
|
|
it 'returns valid validator' do
|
|
|
|
expect(validator).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'configured nodes' do
|
2016-06-16 23:09:34 +05:30
|
|
|
before do
|
|
|
|
node.class_eval do
|
2016-08-24 12:49:21 +05:30
|
|
|
node :object, Object, description: 'test object'
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '.nodes' do
|
|
|
|
it 'has valid nodes' do
|
|
|
|
expect(node.nodes).to include :object
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a node factory' do
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(node.nodes[:object])
|
2016-06-16 23:09:34 +05:30
|
|
|
.to be_an_instance_of Gitlab::Ci::Config::Node::Factory
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a duplicated factory object' do
|
2016-08-24 12:49:21 +05:30
|
|
|
first_factory = node.nodes[:object]
|
|
|
|
second_factory = node.nodes[:object]
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
expect(first_factory).not_to be_equal(second_factory)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|