summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/entry/attributable_spec.rb
blob: fde03c51e2c6da895a2d2c5175c1e2e070a5e21a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'spec_helper'

describe Gitlab::Ci::Config::Entry::Attributable do
  let(:node) { Class.new }
  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
    before do
      allow(instance)
        .to receive(:config)
        .and_return({ name: 'some name', test: 'some test' })
    end

    it 'returns the value of config' do
      expect(instance.name).to eq 'some name'
      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

  context 'config is not a hash' do
    before do
      allow(instance)
        .to receive(:config)
        .and_return('some test')
    end

    it 'returns nil' do
      expect(instance.test).to be_nil
    end
  end
end