gitlab-org--gitlab-foss/spec/lib/expand_variables_spec.rb

65 lines
1.8 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe ExpandVariables do
describe '#expand' do
subject { described_class.expand(value, variables) }
tests = [
{ value: 'key',
result: 'key',
2017-02-22 12:44:44 -05:00
variables: [] },
{ value: 'key$variable',
result: 'key',
2017-02-22 12:44:44 -05:00
variables: [] },
{ value: 'key$variable',
result: 'keyvalue',
variables: [
{ key: 'variable', value: 'value' }
2017-02-22 13:03:32 -05:00
] },
{ value: 'key${variable}',
result: 'keyvalue',
variables: [
{ key: 'variable', value: 'value' }
2017-02-22 13:03:32 -05:00
] },
{ value: 'key$variable$variable2',
result: 'keyvalueresult',
variables: [
{ key: 'variable', value: 'value' },
{ key: 'variable2', value: 'result' }
2017-02-22 13:03:32 -05:00
] },
{ value: 'key${variable}${variable2}',
result: 'keyvalueresult',
variables: [
{ key: 'variable', value: 'value' },
{ key: 'variable2', value: 'result' }
2017-02-22 13:03:32 -05:00
] },
{ value: 'key$variable2$variable',
result: 'keyresultvalue',
variables: [
{ key: 'variable', value: 'value' },
{ key: 'variable2', value: 'result' }
2017-02-22 13:03:32 -05:00
] },
{ value: 'key${variable2}${variable}',
result: 'keyresultvalue',
variables: [
{ key: 'variable', value: 'value' },
{ key: 'variable2', value: 'result' }
2017-02-22 13:03:32 -05:00
] },
2017-03-10 05:20:08 -05:00
{ value: 'review/$CI_COMMIT_REF_NAME',
result: 'review/feature/add-review-apps',
variables: [
2017-03-10 05:20:08 -05:00
{ key: 'CI_COMMIT_REF_NAME', value: 'feature/add-review-apps' }
] }
]
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