summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/pipeline/expression/token_spec.rb
blob: aa807cecb72748c8883c471660f93c70f1872c3c (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
44
45
46
47
# frozen_string_literal: true

require 'fast_spec_helper'

describe Gitlab::Ci::Pipeline::Expression::Token do
  let(:value) { '$VARIABLE' }
  let(:lexeme) { Gitlab::Ci::Pipeline::Expression::Lexeme::Variable }

  subject { described_class.new(value, lexeme) }

  describe '#value' do
    it 'returns raw token value' do
      expect(subject.value).to eq value
    end
  end

  describe '#lexeme' do
    it 'returns raw token lexeme' do
      expect(subject.lexeme).to eq lexeme
    end
  end

  describe '#build' do
    it 'delegates to lexeme after adding a value' do
      expect(lexeme).to receive(:build)
        .with(value, 'some', 'args')

      subject.build('some', 'args')
    end

    it 'allows passing only required arguments' do
      expect(subject.build).to be_an_instance_of(lexeme)
    end
  end

  describe '#type' do
    it 'delegates type query to the lexeme' do
      expect(subject.type).to eq :value
    end
  end

  describe '#to_lexeme' do
    it 'returns raw lexeme syntax component name' do
      expect(subject.to_lexeme).to eq 'variable'
    end
  end
end