summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/badge
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/badge')
-rw-r--r--spec/lib/gitlab/badge/coverage/metadata_spec.rb32
-rw-r--r--spec/lib/gitlab/badge/coverage/report_spec.rb99
-rw-r--r--spec/lib/gitlab/badge/coverage/template_spec.rb182
-rw-r--r--spec/lib/gitlab/badge/pipeline/metadata_spec.rb29
-rw-r--r--spec/lib/gitlab/badge/pipeline/status_spec.rb127
-rw-r--r--spec/lib/gitlab/badge/pipeline/template_spec.rb140
-rw-r--r--spec/lib/gitlab/badge/shared/metadata.rb33
7 files changed, 0 insertions, 642 deletions
diff --git a/spec/lib/gitlab/badge/coverage/metadata_spec.rb b/spec/lib/gitlab/badge/coverage/metadata_spec.rb
deleted file mode 100644
index 725ae03ad74..00000000000
--- a/spec/lib/gitlab/badge/coverage/metadata_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require 'lib/gitlab/badge/shared/metadata'
-
-RSpec.describe Gitlab::Badge::Coverage::Metadata do
- let(:badge) do
- double(project: create(:project), ref: 'feature', job: 'test')
- end
-
- let(:metadata) { described_class.new(badge) }
-
- it_behaves_like 'badge metadata'
-
- describe '#title' do
- it 'returns coverage report title' do
- expect(metadata.title).to eq 'coverage report'
- end
- end
-
- describe '#image_url' do
- it 'returns valid url' do
- expect(metadata.image_url).to include 'badges/feature/coverage.svg'
- end
- end
-
- describe '#link_url' do
- it 'returns valid link' do
- expect(metadata.link_url).to include 'commits/feature'
- end
- end
-end
diff --git a/spec/lib/gitlab/badge/coverage/report_spec.rb b/spec/lib/gitlab/badge/coverage/report_spec.rb
deleted file mode 100644
index 3b5ea3291e4..00000000000
--- a/spec/lib/gitlab/badge/coverage/report_spec.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Badge::Coverage::Report do
- let_it_be(:project) { create(:project) }
- let_it_be(:success_pipeline) { create(:ci_pipeline, :success, project: project) }
- let_it_be(:running_pipeline) { create(:ci_pipeline, :running, project: project) }
- let_it_be(:failure_pipeline) { create(:ci_pipeline, :failed, project: project) }
-
- let_it_be(:builds) do
- [
- create(:ci_build, :success, pipeline: success_pipeline, coverage: 40, created_at: 9.seconds.ago, name: 'coverage'),
- create(:ci_build, :success, pipeline: success_pipeline, coverage: 60, created_at: 8.seconds.ago)
- ]
- end
-
- let(:badge) do
- described_class.new(project, 'master', opts: { job: job_name })
- end
-
- let(:job_name) { nil }
-
- describe '#entity' do
- it 'describes a coverage' do
- expect(badge.entity).to eq 'coverage'
- end
- end
-
- describe '#metadata' do
- it 'returns correct metadata' do
- expect(badge.metadata.image_url).to include 'coverage.svg'
- end
- end
-
- describe '#template' do
- it 'returns correct template' do
- expect(badge.template.key_text).to eq 'coverage'
- end
- end
-
- describe '#status' do
- context 'with no job specified' do
- it 'returns the most recent successful pipeline coverage value' do
- expect(badge.status).to eq(50.00)
- end
-
- context 'and no successful pipelines' do
- before do
- allow(badge).to receive(:successful_pipeline).and_return(nil)
- end
-
- it 'returns nil' do
- expect(badge.status).to eq(nil)
- end
- end
- end
-
- context 'with a blank job name' do
- let(:job_name) { ' ' }
-
- it 'returns the latest successful pipeline coverage value' do
- expect(badge.status).to eq(50.00)
- end
- end
-
- context 'with an unmatching job name specified' do
- let(:job_name) { 'incorrect name' }
-
- it 'returns nil' do
- expect(badge.status).to be_nil
- end
- end
-
- context 'with a matching job name specified' do
- let(:job_name) { 'coverage' }
-
- it 'returns the pipeline coverage value' do
- expect(badge.status).to eq(40.00)
- end
-
- context 'with a more recent running pipeline' do
- let!(:another_build) { create(:ci_build, :success, pipeline: running_pipeline, coverage: 20, created_at: 7.seconds.ago, name: 'coverage') }
-
- it 'returns the running pipeline coverage value' do
- expect(badge.status).to eq(20.00)
- end
- end
-
- context 'with a more recent failed pipeline' do
- let!(:another_build) { create(:ci_build, :success, pipeline: failure_pipeline, coverage: 10, created_at: 6.seconds.ago, name: 'coverage') }
-
- it 'returns the failed pipeline coverage value' do
- expect(badge.status).to eq(10.00)
- end
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/badge/coverage/template_spec.rb b/spec/lib/gitlab/badge/coverage/template_spec.rb
deleted file mode 100644
index ba5c1b2ce6e..00000000000
--- a/spec/lib/gitlab/badge/coverage/template_spec.rb
+++ /dev/null
@@ -1,182 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Badge::Coverage::Template do
- let(:badge) { double(entity: 'coverage', status: 90.00, customization: {}) }
- let(:template) { described_class.new(badge) }
-
- describe '#key_text' do
- it 'says coverage by default' do
- expect(template.key_text).to eq 'coverage'
- end
-
- context 'when custom key_text is defined' do
- before do
- allow(badge).to receive(:customization).and_return({ key_text: "custom text" })
- end
-
- it 'returns custom value' do
- expect(template.key_text).to eq "custom text"
- end
-
- context 'when its size is larger than the max allowed value' do
- before do
- allow(badge).to receive(:customization).and_return({ key_text: 't' * 65 })
- end
-
- it 'returns default value' do
- expect(template.key_text).to eq 'coverage'
- end
- end
- end
- end
-
- describe '#value_text' do
- context 'when coverage is known' do
- it 'returns coverage percentage' do
- expect(template.value_text).to eq '90.00%'
- end
- end
-
- context 'when coverage is known to many digits' do
- before do
- allow(badge).to receive(:status).and_return(92.349)
- end
-
- it 'returns rounded coverage percentage' do
- expect(template.value_text).to eq '92.35%'
- end
- end
-
- context 'when coverage is unknown' do
- before do
- allow(badge).to receive(:status).and_return(nil)
- end
-
- it 'returns string that says coverage is unknown' do
- expect(template.value_text).to eq 'unknown'
- end
- end
- end
-
- describe '#key_width' do
- it 'is fixed by default' do
- expect(template.key_width).to eq 62
- end
-
- context 'when custom key_width is defined' do
- before do
- allow(badge).to receive(:customization).and_return({ key_width: 101 })
- end
-
- it 'returns custom value' do
- expect(template.key_width).to eq 101
- end
-
- context 'when it is larger than the max allowed value' do
- before do
- allow(badge).to receive(:customization).and_return({ key_width: 513 })
- end
-
- it 'returns default value' do
- expect(template.key_width).to eq 62
- end
- end
- end
- end
-
- describe '#value_width' do
- context 'when coverage is known' do
- it 'is narrower when coverage is known' do
- expect(template.value_width).to eq 54
- end
- end
-
- context 'when coverage is unknown' do
- before do
- allow(badge).to receive(:status).and_return(nil)
- end
-
- it 'is wider when coverage is unknown to fit text' do
- expect(template.value_width).to eq 58
- end
- end
- end
-
- describe '#key_color' do
- it 'always has the same color' do
- expect(template.key_color).to eq '#555'
- end
- end
-
- describe '#value_color' do
- context 'when coverage is good' do
- before do
- allow(badge).to receive(:status).and_return(98)
- end
-
- it 'is green' do
- expect(template.value_color).to eq '#4c1'
- end
- end
-
- context 'when coverage is acceptable' do
- before do
- allow(badge).to receive(:status).and_return(90)
- end
-
- it 'is green-orange' do
- expect(template.value_color).to eq '#a3c51c'
- end
- end
-
- context 'when coverage is medium' do
- before do
- allow(badge).to receive(:status).and_return(75)
- end
-
- it 'is orange-yellow' do
- expect(template.value_color).to eq '#dfb317'
- end
- end
-
- context 'when coverage is low' do
- before do
- allow(badge).to receive(:status).and_return(50)
- end
-
- it 'is red' do
- expect(template.value_color).to eq '#e05d44'
- end
- end
-
- context 'when coverage is unknown' do
- before do
- allow(badge).to receive(:status).and_return(nil)
- end
-
- it 'is grey' do
- expect(template.value_color).to eq '#9f9f9f'
- end
- end
- end
-
- describe '#width' do
- context 'when coverage is known' do
- it 'returns the key width plus value width' do
- expect(template.width).to eq 116
- end
- end
-
- context 'when coverage is unknown' do
- before do
- allow(badge).to receive(:status).and_return(nil)
- end
-
- it 'returns key width plus wider value width' do
- expect(template.width).to eq 120
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/badge/pipeline/metadata_spec.rb b/spec/lib/gitlab/badge/pipeline/metadata_spec.rb
deleted file mode 100644
index c8ed0c8ea29..00000000000
--- a/spec/lib/gitlab/badge/pipeline/metadata_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require 'lib/gitlab/badge/shared/metadata'
-
-RSpec.describe Gitlab::Badge::Pipeline::Metadata do
- let(:badge) { double(project: create(:project), ref: 'feature') }
- let(:metadata) { described_class.new(badge) }
-
- it_behaves_like 'badge metadata'
-
- describe '#title' do
- it 'returns build status title' do
- expect(metadata.title).to eq 'pipeline status'
- end
- end
-
- describe '#image_url' do
- it 'returns valid url' do
- expect(metadata.image_url).to include 'badges/feature/pipeline.svg'
- end
- end
-
- describe '#link_url' do
- it 'returns valid link' do
- expect(metadata.link_url).to include 'commits/feature'
- end
- end
-end
diff --git a/spec/lib/gitlab/badge/pipeline/status_spec.rb b/spec/lib/gitlab/badge/pipeline/status_spec.rb
deleted file mode 100644
index b5dabca0477..00000000000
--- a/spec/lib/gitlab/badge/pipeline/status_spec.rb
+++ /dev/null
@@ -1,127 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Badge::Pipeline::Status do
- let(:project) { create(:project, :repository) }
- let(:sha) { project.commit.sha }
- let(:branch) { 'master' }
- let(:badge) { described_class.new(project, branch) }
-
- describe '#entity' do
- it 'always says pipeline' do
- expect(badge.entity).to eq 'pipeline'
- end
- end
-
- describe '#template' do
- it 'returns badge template' do
- expect(badge.template.key_text).to eq 'pipeline'
- end
- end
-
- describe '#metadata' do
- it 'returns badge metadata' do
- expect(badge.metadata.image_url).to include 'badges/master/pipeline.svg'
- end
- end
-
- context 'pipeline exists', :sidekiq_might_not_need_inline do
- let!(:pipeline) { create_pipeline(project, sha, branch) }
-
- context 'pipeline success' do
- before do
- pipeline.success!
- end
-
- describe '#status' do
- it 'is successful' do
- expect(badge.status).to eq 'success'
- end
- end
- end
-
- context 'pipeline failed' do
- before do
- pipeline.drop!
- end
-
- describe '#status' do
- it 'failed' do
- expect(badge.status).to eq 'failed'
- end
- end
- end
-
- context 'when outdated pipeline for given ref exists' do
- before do
- pipeline.success!
-
- old_pipeline = create_pipeline(project, '11eeffdd', branch)
- old_pipeline.drop!
- end
-
- it 'does not take outdated pipeline into account' do
- expect(badge.status).to eq 'success'
- end
- end
-
- context 'when multiple pipelines exist for given sha' do
- before do
- pipeline.drop!
-
- new_pipeline = create_pipeline(project, sha, branch)
- new_pipeline.success!
- end
-
- it 'does not take outdated pipeline into account' do
- expect(badge.status).to eq 'success'
- end
- end
-
- context 'when ignored_skipped is set to true' do
- let(:new_badge) { described_class.new(project, branch, opts: { ignore_skipped: true }) }
-
- before do
- pipeline.skip!
- end
-
- describe '#status' do
- it 'uses latest non-skipped status' do
- expect(new_badge.status).not_to eq 'skipped'
- end
- end
- end
-
- context 'when ignored_skipped is set to false' do
- let(:new_badge) { described_class.new(project, branch, opts: { ignore_skipped: false }) }
-
- before do
- pipeline.skip!
- end
-
- describe '#status' do
- it 'uses latest status' do
- expect(new_badge.status).to eq 'skipped'
- end
- end
- end
- end
-
- context 'build does not exist' do
- describe '#status' do
- it 'is unknown' do
- expect(badge.status).to eq 'unknown'
- end
- end
- end
-
- def create_pipeline(project, sha, branch)
- pipeline = create(:ci_empty_pipeline,
- project: project,
- sha: sha,
- ref: branch)
-
- create(:ci_build, pipeline: pipeline, stage: 'notify')
- end
-end
diff --git a/spec/lib/gitlab/badge/pipeline/template_spec.rb b/spec/lib/gitlab/badge/pipeline/template_spec.rb
deleted file mode 100644
index c78e95852f3..00000000000
--- a/spec/lib/gitlab/badge/pipeline/template_spec.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Badge::Pipeline::Template do
- let(:badge) { double(entity: 'pipeline', status: 'success', customization: {}) }
- let(:template) { described_class.new(badge) }
-
- describe '#key_text' do
- it 'says pipeline by default' do
- expect(template.key_text).to eq 'pipeline'
- end
-
- context 'when custom key_text is defined' do
- before do
- allow(badge).to receive(:customization).and_return({ key_text: 'custom text' })
- end
-
- it 'returns custom value' do
- expect(template.key_text).to eq 'custom text'
- end
-
- context 'when its size is larger than the max allowed value' do
- before do
- allow(badge).to receive(:customization).and_return({ key_text: 't' * 65 })
- end
-
- it 'returns default value' do
- expect(template.key_text).to eq 'pipeline'
- end
- end
- end
- end
-
- describe '#value_text' do
- it 'is status value' do
- expect(template.value_text).to eq 'passed'
- end
- end
-
- describe '#key_width' do
- it 'is fixed by default' do
- expect(template.key_width).to eq 62
- end
-
- context 'when custom key_width is defined' do
- before do
- allow(badge).to receive(:customization).and_return({ key_width: 101 })
- end
-
- it 'returns custom value' do
- expect(template.key_width).to eq 101
- end
-
- context 'when it is larger than the max allowed value' do
- before do
- allow(badge).to receive(:customization).and_return({ key_width: 513 })
- end
-
- it 'returns default value' do
- expect(template.key_width).to eq 62
- end
- end
- end
- end
-
- describe 'widths and text anchors' do
- it 'has fixed width and text anchors' do
- expect(template.width).to eq 116
- expect(template.key_width).to eq 62
- expect(template.value_width).to eq 54
- expect(template.key_text_anchor).to eq 31
- expect(template.value_text_anchor).to eq 89
- end
- end
-
- describe '#key_color' do
- it 'is always the same' do
- expect(template.key_color).to eq '#555'
- end
- end
-
- describe '#value_color' do
- context 'when status is success' do
- it 'has expected color' do
- expect(template.value_color).to eq '#4c1'
- end
- end
-
- context 'when status is failed' do
- before do
- allow(badge).to receive(:status).and_return('failed')
- end
-
- it 'has expected color' do
- expect(template.value_color).to eq '#e05d44'
- end
- end
-
- context 'when status is running' do
- before do
- allow(badge).to receive(:status).and_return('running')
- end
-
- it 'has expected color' do
- expect(template.value_color).to eq '#dfb317'
- end
- end
-
- context 'when status is preparing' do
- before do
- allow(badge).to receive(:status).and_return('preparing')
- end
-
- it 'has expected color' do
- expect(template.value_color).to eq '#a7a7a7'
- end
- end
-
- context 'when status is unknown' do
- before do
- allow(badge).to receive(:status).and_return('unknown')
- end
-
- it 'has expected color' do
- expect(template.value_color).to eq '#9f9f9f'
- end
- end
-
- context 'when status does not match any known statuses' do
- before do
- allow(badge).to receive(:status).and_return('invalid')
- end
-
- it 'has expected color' do
- expect(template.value_color).to eq '#9f9f9f'
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/badge/shared/metadata.rb b/spec/lib/gitlab/badge/shared/metadata.rb
deleted file mode 100644
index c99a65bb2f4..00000000000
--- a/spec/lib/gitlab/badge/shared/metadata.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.shared_examples 'badge metadata' do
- describe '#to_html' do
- let(:html) { Nokogiri::HTML.parse(metadata.to_html) }
- let(:a_href) { html.at('a') }
-
- it 'points to link' do
- expect(a_href[:href]).to eq metadata.link_url
- end
-
- it 'contains clickable image' do
- expect(a_href.children.first.name).to eq 'img'
- end
- end
-
- describe '#to_markdown' do
- subject { metadata.to_markdown }
-
- it { is_expected.to include metadata.image_url }
- it { is_expected.to include metadata.link_url }
- end
-
- describe '#to_asciidoc' do
- subject { metadata.to_asciidoc }
-
- it { is_expected.to include metadata.image_url }
- it { is_expected.to include metadata.link_url }
- it { is_expected.to include 'image:' }
- it { is_expected.to include 'link=' }
- it { is_expected.to include 'title=' }
- end
-end