debian-mirror-gitlab/spec/lib/gitlab/config/entry/attributable_spec.rb

66 lines
1.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Config::Entry::Attributable do
2018-03-17 18:26:18 +05:30
let(:node) do
Class.new do
2019-02-15 15:39:39 +05:30
include Gitlab::Config::Entry::Attributable
2018-03-17 18:26:18 +05:30
end
end
2016-09-13 17:45:13 +05:30
let(:instance) { node.new }
before do
node.class_eval do
attributes :name, :test
end
end
2018-03-17 18:26:18 +05:30
context 'when config is a hash' do
2016-09-13 17:45:13 +05:30
before do
allow(instance)
.to receive(:config)
.and_return({ name: 'some name', test: 'some test' })
end
it 'returns the value of config' do
2019-10-12 21:52:04 +05:30
expect(instance).to have_name
2016-09-13 17:45:13 +05:30
expect(instance.name).to eq 'some name'
2019-10-12 21:52:04 +05:30
expect(instance).to have_test
2016-09-13 17:45:13 +05:30
expect(instance.test).to eq 'some test'
end
it 'returns no method error for unknown attributes' do
expect { instance.unknown }.to raise_error(NoMethodError)
end
end
2018-03-17 18:26:18 +05:30
context 'when config is not a hash' do
2016-09-13 17:45:13 +05:30
before do
allow(instance)
.to receive(:config)
.and_return('some test')
end
it 'returns nil' do
2019-10-12 21:52:04 +05:30
expect(instance).not_to have_test
2016-09-13 17:45:13 +05:30
expect(instance.test).to be_nil
end
end
2018-03-17 18:26:18 +05:30
context 'when method is already defined in a superclass' do
it 'raises an error' do
expectation = expect do
Class.new(String) do
2019-02-15 15:39:39 +05:30
include Gitlab::Config::Entry::Attributable
2018-03-17 18:26:18 +05:30
attributes :length
end
end
2020-04-08 14:13:33 +05:30
expectation.to raise_error(ArgumentError, /Method 'length' already defined in/)
2018-03-17 18:26:18 +05:30
end
end
2016-09-13 17:45:13 +05:30
end