BigW Consortium Gitlab

Commit 04108611 by Grzegorz Bizon

Add specs for attributable aspect of ci config entry

parent 4509594e
...@@ -8,7 +8,9 @@ module Gitlab ...@@ -8,7 +8,9 @@ module Gitlab
class_methods do class_methods do
def attributes(*attributes) def attributes(*attributes)
attributes.flatten.each do |attribute| attributes.flatten.each do |attribute|
raise ArgumentError if method_defined?(attribute) if method_defined?(attribute)
raise ArgumentError, 'Method already defined!'
end
define_method(attribute) do define_method(attribute) do
return unless config.is_a?(Hash) return unless config.is_a?(Hash)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Entry::Attributable do describe Gitlab::Ci::Config::Entry::Attributable do
let(:node) { Class.new } let(:node) do
Class.new do
include Gitlab::Ci::Config::Entry::Attributable
end
end
let(:instance) { node.new } let(:instance) { node.new }
before do before do
node.include(described_class)
node.class_eval do node.class_eval do
attributes :name, :test attributes :name, :test
end end
end end
context 'config is a hash' do context 'when config is a hash' do
before do before do
allow(instance) allow(instance)
.to receive(:config) .to receive(:config)
...@@ -29,7 +32,7 @@ describe Gitlab::Ci::Config::Entry::Attributable do ...@@ -29,7 +32,7 @@ describe Gitlab::Ci::Config::Entry::Attributable do
end end
end end
context 'config is not a hash' do context 'when config is not a hash' do
before do before do
allow(instance) allow(instance)
.to receive(:config) .to receive(:config)
...@@ -40,4 +43,18 @@ describe Gitlab::Ci::Config::Entry::Attributable do ...@@ -40,4 +43,18 @@ describe Gitlab::Ci::Config::Entry::Attributable do
expect(instance.test).to be_nil expect(instance.test).to be_nil
end end
end end
context 'when method is already defined in a superclass' do
it 'raises an error' do
expectation = expect do
Class.new(String) do
include Gitlab::Ci::Config::Entry::Attributable
attributes :length
end
end
expectation.to raise_error(ArgumentError, 'Method already defined!')
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