summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
blob: 019a2ed184dabec3166844be6ff6824e97742d44 (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
require 'spec_helper'

describe Gitlab::Ci::Pipeline::Expression::Lexeme::Equals do
  let(:left) { double('left') }
  let(:right) { double('right') }

  describe '.build' do
    it 'creates a new instance of the token' do
      expect(described_class.build('==', left, right))
        .to be_a(described_class)
    end
  end

  describe '.type' do
    it 'is an operator' do
      expect(described_class.type).to eq :operator
    end
  end

  describe '#evaluate' do
    it 'returns false when left and right are not equal' do
      allow(left).to receive(:evaluate).and_return(1)
      allow(right).to receive(:evaluate).and_return(2)

      operator = described_class.new(left, right)

      expect(operator.evaluate(VARIABLE: 3)).to eq false
    end

    it 'returns true when left and right are equal' do
      allow(left).to receive(:evaluate).and_return(1)
      allow(right).to receive(:evaluate).and_return(1)

      operator = described_class.new(left, right)

      expect(operator.evaluate(VARIABLE: 3)).to eq true
    end
  end
end