Welcome to mirror list, hosted at ThFree Co, Russian Federation.

not_equals_spec.rb « lexeme « expression « pipeline « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 38d30c9035a2702ba80f38f778847fd41f318590 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'spec_helper'

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

  describe '.build' do
    context 'with non-evaluable operands' do
      it 'creates a new instance of the token' do
        expect { described_class.build('!=', left, right) }
          .to raise_error Gitlab::Ci::Pipeline::Expression::Lexeme::Operator::OperatorError
      end
    end

    context 'with evaluable operands' do
      it 'creates a new instance of the token' do
        allow(left).to receive(:evaluate).and_return('my-string')
        allow(right).to receive(:evaluate).and_return('my-string')

        expect(described_class.build('!=', left, right))
          .to be_a(described_class)
      end
    end
  end

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

  describe '.precedence' do
    it 'has a precedence' do
      expect(described_class.precedence).to be_an Integer
    end
  end

  describe '#evaluate' do
    let(:operator) { described_class.new(left, right) }

    subject { operator.evaluate }

    before do
      allow(left).to receive(:evaluate).and_return(left_value)
      allow(right).to receive(:evaluate).and_return(right_value)
    end

    context 'when left and right are equal' do
      using RSpec::Parameterized::TableSyntax

      where(:left_value, :right_value) do
        'string' | 'string'
        1        | 1
        ''       | ''
        nil      | nil
      end

      with_them do
        it { is_expected.to eq(false) }
      end
    end

    context 'when left and right are not equal' do
      where(:left_value, :right_value) do
        ['one string', 'two string', 1, 2, '', nil, false, true].permutation(2).to_a
      end

      with_them do
        it { is_expected.to eq(true) }
      end
    end
  end
end