summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Camargo <leandroico@gmail.com>2016-12-06 02:39:59 -0200
committerLeandro Camargo <leandroico@gmail.com>2017-01-25 01:07:44 -0200
commitf8bec0d1fb05d2c3e87a0470579ee7a650ade23c (patch)
tree028fc0ef685c0ef7d33c6c80982a3d52d2e5505d
parent6323cd7203dbf1850e7939e81db4b1a9c6cf6d76 (diff)
downloadgitlab-ce-f8bec0d1fb05d2c3e87a0470579ee7a650ade23c.tar.gz
Improve specs styles/organization and add some more specs
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/entry/coverage_spec.rb25
-rw-r--r--spec/lib/gitlab/ci/config/entry/global_spec.rb18
-rw-r--r--spec/models/ci/build_spec.rb13
4 files changed, 38 insertions, 20 deletions
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index 3ffcfaa1f29..b1e09350847 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -20,7 +20,7 @@ module Ci
it { is_expected.to include(coverage_regex: '\(\d+\.\d+\) covered') }
end
- context 'but \'rspec\' job also has coverage set' do
+ context "but 'rspec' job also has coverage set" do
before do
config_base[:rspec][:coverage] = '/Code coverage: \d+\.\d+/'
end
diff --git a/spec/lib/gitlab/ci/config/entry/coverage_spec.rb b/spec/lib/gitlab/ci/config/entry/coverage_spec.rb
index 0549dbc732b..8f989ebd732 100644
--- a/spec/lib/gitlab/ci/config/entry/coverage_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/coverage_spec.rb
@@ -4,12 +4,31 @@ describe Gitlab::Ci::Config::Entry::Coverage do
let(:entry) { described_class.new(config) }
describe 'validations' do
- context 'when entry config value is correct' do
+ context "when entry config value is correct without surrounding '/'" do
let(:config) { 'Code coverage: \d+\.\d+' }
describe '#value' do
subject { entry.value }
- it { is_expected.to eq config }
+ it { is_expected.to eq(config) }
+ end
+
+ describe '#errors' do
+ subject { entry.errors }
+ it { is_expected.to be_empty }
+ end
+
+ describe '#valid?' do
+ subject { entry }
+ it { is_expected.to be_valid }
+ end
+ end
+
+ context "when entry config value is correct with surrounding '/'" do
+ let(:config) { '/Code coverage: \d+\.\d+/' }
+
+ describe '#value' do
+ subject { entry.value }
+ it { is_expected.to eq(config[1...-1]) }
end
describe '#errors' do
@@ -28,7 +47,7 @@ describe Gitlab::Ci::Config::Entry::Coverage do
describe '#errors' do
subject { entry.errors }
- it { is_expected.to include /coverage config must be a regular expression/ }
+ it { is_expected.to include(/coverage config must be a regular expression/) }
end
describe '#valid?' do
diff --git a/spec/lib/gitlab/ci/config/entry/global_spec.rb b/spec/lib/gitlab/ci/config/entry/global_spec.rb
index 66a1380bc61..7b7f5761ebd 100644
--- a/spec/lib/gitlab/ci/config/entry/global_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/global_spec.rb
@@ -4,19 +4,17 @@ describe Gitlab::Ci::Config::Entry::Global do
let(:global) { described_class.new(hash) }
describe '.nodes' do
- subject { described_class.nodes }
-
- it { is_expected.to be_a Hash }
+ it 'returns a hash' do
+ expect(described_class.nodes).to be_a(Hash)
+ end
context 'when filtering all the entry/node names' do
- subject { described_class.nodes.keys }
-
- let(:result) do
- %i[before_script image services after_script variables stages types
- cache coverage]
+ it 'contains the expected node names' do
+ node_names = described_class.nodes.keys
+ expect(node_names).to match_array(%i[before_script image services
+ after_script variables stages
+ types cache coverage])
end
-
- it { is_expected.to match_array result }
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 7baaef9c85e..52cc45f07b2 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -251,12 +251,13 @@ describe Ci::Build, :models do
end
describe '#update_coverage' do
- it 'grants coverage_regex method is called inside of it' do
- build.coverage_regex = '\(\d+.\d+\%\) covered'
- allow(build).to receive(:trace) { 'Coverage 1033 / 1051 LOC (98.29%) covered' }
- allow(build).to receive(:coverage_regex).and_call_original
- expect(build).to receive(:update_attributes).with(coverage: 98.29) { true }
- expect(build.update_coverage).to be true
+ context "regarding coverage_regex's value," do
+ it "saves the correct extracted coverage value" do
+ build.coverage_regex = '\(\d+.\d+\%\) covered'
+ allow(build).to receive(:trace) { 'Coverage 1033 / 1051 LOC (98.29%) covered' }
+ expect(build).to receive(:update_attributes).with(coverage: 98.29) { true }
+ expect(build.update_coverage).to be true
+ end
end
end