summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-25 18:26:55 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-25 18:26:55 +0200
commit04108611716c0f1bb00092077ad5e31785675490 (patch)
tree3fed8b7f66b790887ddaee21197fd9fe946c739a
parent4509594e206f93cdb54d80ae96fe7ad3d6a8fa4b (diff)
downloadgitlab-ce-04108611716c0f1bb00092077ad5e31785675490.tar.gz
Add specs for attributable aspect of ci config entry
-rw-r--r--lib/gitlab/ci/config/entry/attributable.rb4
-rw-r--r--spec/lib/gitlab/ci/config/entry/attributable_spec.rb27
2 files changed, 25 insertions, 6 deletions
diff --git a/lib/gitlab/ci/config/entry/attributable.rb b/lib/gitlab/ci/config/entry/attributable.rb
index 24ff862a142..3e87a09704e 100644
--- a/lib/gitlab/ci/config/entry/attributable.rb
+++ b/lib/gitlab/ci/config/entry/attributable.rb
@@ -8,7 +8,9 @@ module Gitlab
class_methods do
def attributes(*attributes)
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
return unless config.is_a?(Hash)
diff --git a/spec/lib/gitlab/ci/config/entry/attributable_spec.rb b/spec/lib/gitlab/ci/config/entry/attributable_spec.rb
index fde03c51e2c..b028b771375 100644
--- a/spec/lib/gitlab/ci/config/entry/attributable_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/attributable_spec.rb
@@ -1,18 +1,21 @@
require 'spec_helper'
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 }
before do
- node.include(described_class)
-
node.class_eval do
attributes :name, :test
end
end
- context 'config is a hash' do
+ context 'when config is a hash' do
before do
allow(instance)
.to receive(:config)
@@ -29,7 +32,7 @@ describe Gitlab::Ci::Config::Entry::Attributable do
end
end
- context 'config is not a hash' do
+ context 'when config is not a hash' do
before do
allow(instance)
.to receive(:config)
@@ -40,4 +43,18 @@ describe Gitlab::Ci::Config::Entry::Attributable do
expect(instance.test).to be_nil
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