diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-04-16 21:52:01 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-04-18 14:17:48 +0300 |
commit | cf3e3effb01215c2556ba509d3cb4debe1d901e8 (patch) | |
tree | c8d56d2aacf2c0e0818fbc7a94ea7e89c45c8d6e | |
parent | a6260b1eb7b4f30817d0cc5dbd80c860b5ed8a31 (diff) |
Minor refactoring in code related to job variables
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 6 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 43 |
2 files changed, 25 insertions, 24 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index e152de590de..209da7ad81f 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -45,11 +45,7 @@ module Ci end def job_variables(name) - if job = @jobs[name.to_sym] - job[:variables] || [] - else - [] - end + @jobs[name.to_sym].try(:fetch, :variables, []) || [] end private diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 45f08c95cc3..9a014c4b6c6 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -345,50 +345,55 @@ module Ci end end - describe "Variables" do + describe 'Variables' do context 'when global variables are defined' do - it 'returns variables' do + it 'returns global variables' do variables = { - var1: "value1", - var2: "value2", + VAR1: 'value1', + VAR2: 'value2', } + config = YAML.dump({ - variables: variables, - before_script: ["pwd"], - rspec: { script: "rspec" } - }) + variables: variables, + before_script: ['pwd'], + rspec: { script: 'rspec' } + }) config_processor = GitlabCiYamlProcessor.new(config, path) + expect(config_processor.global_variables).to eq(variables) end end context 'when job variables are defined' do - let(:job_variables) { { KEY1: 'value1', SOME_KEY_2: 'value2' } } - let(:yaml_config) do - YAML.dump( + it 'returns job variables' do + variables = { + KEY1: 'value1', + SOME_KEY_2: 'value2' + } + + config = YAML.dump( { before_script: ['pwd'], rspec: { - variables: job_variables, + variables: variables, script: 'rspec' } }) - end - it 'returns job variables' do - config = GitlabCiYamlProcessor.new(yaml_config, path) + config_processor = GitlabCiYamlProcessor.new(config, path) - expect(config.job_variables(:rspec)).to eq job_variables + expect(config_processor.job_variables(:rspec)).to eq variables end end context 'when job variables are not defined' do it 'returns empty array' do config = YAML.dump({ - before_script: ["pwd"], - rspec: { script: "rspec" } - }) + before_script: ['pwd'], + rspec: { script: 'rspec' } + }) config_processor = GitlabCiYamlProcessor.new(config, path) + expect(config_processor.job_variables(:rspec)).to eq [] end end |