expand_variables_spec.rb 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9
require 'spec_helper'

describe ExpandVariables do
  describe '#expand' do
    subject { described_class.expand(value, variables) }

    tests = [
      { value: 'key',
        result: 'key',
10
        variables: [] },
11 12
      { value: 'key$variable',
        result: 'key',
13
        variables: [] },
14 15 16 17
      { value: 'key$variable',
        result: 'keyvalue',
        variables: [
          { key: 'variable', value: 'value' }
Douwe Maan's avatar
Douwe Maan committed
18
        ] },
19 20 21 22
      { value: 'key${variable}',
        result: 'keyvalue',
        variables: [
          { key: 'variable', value: 'value' }
Douwe Maan's avatar
Douwe Maan committed
23
        ] },
24 25 26 27
      { value: 'key$variable$variable2',
        result: 'keyvalueresult',
        variables: [
          { key: 'variable', value: 'value' },
28
          { key: 'variable2', value: 'result' }
Douwe Maan's avatar
Douwe Maan committed
29
        ] },
30 31 32 33 34
      { value: 'key${variable}${variable2}',
        result: 'keyvalueresult',
        variables: [
          { key: 'variable', value: 'value' },
          { key: 'variable2', value: 'result' }
Douwe Maan's avatar
Douwe Maan committed
35
        ] },
36 37 38 39
      { value: 'key$variable2$variable',
        result: 'keyresultvalue',
        variables: [
          { key: 'variable', value: 'value' },
40
          { key: 'variable2', value: 'result' }
Douwe Maan's avatar
Douwe Maan committed
41
        ] },
42 43 44 45 46
      { value: 'key${variable2}${variable}',
        result: 'keyresultvalue',
        variables: [
          { key: 'variable', value: 'value' },
          { key: 'variable2', value: 'result' }
Douwe Maan's avatar
Douwe Maan committed
47
        ] },
48
      { value: 'review/$CI_COMMIT_REF_NAME',
49 50
        result: 'review/feature/add-review-apps',
        variables: [
51
          { key: 'CI_COMMIT_REF_NAME', value: 'feature/add-review-apps' }
52
        ] }
53 54 55 56 57 58 59 60 61 62 63 64
    ]

    tests.each do |test|
      context "#{test[:value]} resolves to #{test[:result]}" do
        let(:value) { test[:value] }
        let(:variables) { test[:variables] }

        it { is_expected.to eq(test[:result]) }
      end
    end
  end
end