summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/node/global_spec.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-15 20:14:25 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-15 20:14:25 +0200
commitd8670e114af1e21c48878afe8af16cc5628861fa (patch)
treec84b3fb5398b9629491ab30549a9cbd89b3495c3 /spec/lib/gitlab/ci/config/node/global_spec.rb
parent2d495fce529cc3ac15f7096ddf9962db0fbd1e23 (diff)
parent32a5ff70d771e7bff4e5c7b42fe95a966fa47a96 (diff)
downloadgitlab-ce-fix/status-of-pipeline-without-builds.tar.gz
Merge branch 'master' into fix/status-of-pipeline-without-buildsfix/status-of-pipeline-without-builds
* master: (198 commits) Set inverse_of for Project/Services relation Fix admin hooks spec Prevent default disabled buttons and links. Add index on `requested_at` to the `members` table Rearrange order of tabs Fix admin active tab tests Show created_at in table column Nest li elements directly under ul Move builds tab to admin overview Add monitoring link with subtabs Add sub links to overview Add counter for abuse reports Remove admin layout-nav counters Move admin nav to horizontal layout nav Eager load project relations in IssueParser Use validate and required for environment and project Award Emoji can't be awarded on system notes backend Get rid of Gitlab::ShellEnv Update CHANGELOG. Fix project star tooltip on the fly. ... Conflicts: app/services/ci/create_builds_service.rb
Diffstat (limited to 'spec/lib/gitlab/ci/config/node/global_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/config/node/global_spec.rb104
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb
new file mode 100644
index 00000000000..b1972172435
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/node/global_spec.rb
@@ -0,0 +1,104 @@
+require 'spec_helper'
+
+describe Gitlab::Ci::Config::Node::Global do
+ let(:global) { described_class.new(hash) }
+
+ describe '#allowed_nodes' do
+ it 'can contain global config keys' do
+ expect(global.allowed_nodes).to include :before_script
+ end
+
+ it 'returns a hash' do
+ expect(global.allowed_nodes).to be_a Hash
+ end
+ end
+
+ context 'when hash is valid' do
+ let(:hash) do
+ { before_script: ['ls', 'pwd'] }
+ end
+
+ describe '#process!' do
+ before { global.process! }
+
+ it 'creates nodes hash' do
+ expect(global.nodes).to be_an Array
+ end
+
+ it 'creates node object for each entry' do
+ expect(global.nodes.count).to eq 1
+ end
+
+ it 'creates node object using valid class' do
+ expect(global.nodes.first)
+ .to be_an_instance_of Gitlab::Ci::Config::Node::Script
+ end
+
+ it 'sets correct description for nodes' do
+ expect(global.nodes.first.description)
+ .to eq 'Script that will be executed before each job.'
+ end
+ end
+
+ describe '#leaf?' do
+ it 'is not leaf' do
+ expect(global).not_to be_leaf
+ end
+ end
+
+ describe '#before_script' do
+ context 'when processed' do
+ before { global.process! }
+
+ it 'returns correct script' do
+ expect(global.before_script).to eq "ls\npwd"
+ end
+ end
+
+ context 'when not processed' do
+ it 'returns nil' do
+ expect(global.before_script).to be nil
+ end
+ end
+ end
+ end
+
+ context 'when hash is not valid' do
+ before { global.process! }
+
+ let(:hash) do
+ { before_script: 'ls' }
+ end
+
+ describe '#valid?' do
+ it 'is not valid' do
+ expect(global).not_to be_valid
+ end
+ end
+
+ describe '#errors' do
+ it 'reports errors from child nodes' do
+ expect(global.errors)
+ .to include 'before_script should be an array of strings'
+ end
+ end
+
+ describe '#before_script' do
+ it 'raises error' do
+ expect { global.before_script }.to raise_error(
+ Gitlab::Ci::Config::Node::Entry::InvalidError
+ )
+ end
+ end
+ end
+
+ context 'when value is not a hash' do
+ let(:hash) { [] }
+
+ describe '#valid?' do
+ it 'is not valid' do
+ expect(global).not_to be_valid
+ end
+ end
+ end
+end