diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-11 12:16:14 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-15 15:39:46 +0300 |
commit | f3de46e6b0d4cc61e00c884753a8c9eec66f66c4 (patch) | |
tree | c94491b355df3a161a7a805f2d7794ece07384e6 /spec/lib | |
parent | 9f0b46c05aef9d0352bfaa5e42e34143227de8ff (diff) |
Refactor badge template and metadata classes
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/badge/build/metadata_spec.rb | 25 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/build/status_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/build/template_spec.rb | 22 |
3 files changed, 39 insertions, 44 deletions
diff --git a/spec/lib/gitlab/badge/build/metadata_spec.rb b/spec/lib/gitlab/badge/build/metadata_spec.rb index ad5388215c2..4044a82d16c 100644 --- a/spec/lib/gitlab/badge/build/metadata_spec.rb +++ b/spec/lib/gitlab/badge/build/metadata_spec.rb @@ -1,16 +1,15 @@ require 'spec_helper' describe Gitlab::Badge::Build::Metadata do - let(:project) { create(:project) } - let(:branch) { 'master' } - let(:badge) { described_class.new(project, branch) } + let(:badge) { double(project: create(:project), ref: 'feature') } + let(:metadata) { described_class.new(badge) } describe '#to_html' do - let(:html) { Nokogiri::HTML.parse(badge.to_html) } + 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 badge.link_url + expect(a_href[:href]).to eq metadata.link_url end it 'contains clickable image' do @@ -19,19 +18,21 @@ describe Gitlab::Badge::Build::Metadata do end describe '#to_markdown' do - subject { badge.to_markdown } + subject { metadata.to_markdown } - it { is_expected.to include badge.image_url } - it { is_expected.to include badge.link_url } + it { is_expected.to include metadata.image_url } + it { is_expected.to include metadata.link_url } end describe '#image_url' do - subject { badge.image_url } - it { is_expected.to include "badges/#{branch}/build.svg" } + it 'returns valid url' do + expect(metadata.image_url).to include 'badges/feature/build.svg' + end end describe '#link_url' do - subject { badge.link_url } - it { is_expected.to include "commits/#{branch}" } + it 'returns valid link' do + expect(metadata.link_url).to include 'commits/feature' + end end end diff --git a/spec/lib/gitlab/badge/build/status_spec.rb b/spec/lib/gitlab/badge/build/status_spec.rb index fa5bc068918..38eebb2a176 100644 --- a/spec/lib/gitlab/badge/build/status_spec.rb +++ b/spec/lib/gitlab/badge/build/status_spec.rb @@ -6,6 +6,18 @@ describe Gitlab::Badge::Build::Status do let(:branch) { 'master' } let(:badge) { described_class.new(project, branch) } + describe '#entity' do + it 'always says build' do + expect(badge.entity).to eq 'build' + end + end + + describe '#template' do + it 'returns badge template' do + expect(badge.template.key_text).to eq 'build' + end + end + describe '#metadata' do it 'returns badge metadata' do expect(badge.metadata.image_url) @@ -13,12 +25,6 @@ describe Gitlab::Badge::Build::Status do end end - describe '#key_text' do - it 'always says build' do - expect(badge.key_text).to eq 'build' - end - end - context 'build exists' do let!(:build) { create_build(project, sha, branch) } @@ -30,12 +36,6 @@ describe Gitlab::Badge::Build::Status do expect(badge.status).to eq 'success' end end - - describe '#value_text' do - it 'returns correct value text' do - expect(badge.value_text).to eq 'success' - end - end end context 'build failed' do @@ -46,12 +46,6 @@ describe Gitlab::Badge::Build::Status do expect(badge.status).to eq 'failed' end end - - describe '#value_text' do - it 'has correct value text' do - expect(badge.value_text).to eq 'failed' - end - end end context 'when outdated pipeline for given ref exists' do @@ -87,12 +81,6 @@ describe Gitlab::Badge::Build::Status do expect(badge.status).to eq 'unknown' end end - - describe '#value_text' do - it 'has correct value text' do - expect(badge.value_text).to eq 'unknown' - end - end end def create_build(project, sha, branch) diff --git a/spec/lib/gitlab/badge/build/template_spec.rb b/spec/lib/gitlab/badge/build/template_spec.rb index 86dead3c54e..a7e21fb8bb1 100644 --- a/spec/lib/gitlab/badge/build/template_spec.rb +++ b/spec/lib/gitlab/badge/build/template_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe Gitlab::Badge::Build::Template do - let(:status) { 'success' } - let(:template) { described_class.new(status) } + let(:badge) { double(entity: 'build', status: 'success') } + let(:template) { described_class.new(badge) } describe '#key_text' do it 'is always says build' do @@ -34,15 +34,15 @@ describe Gitlab::Badge::Build::Template do describe '#value_color' do context 'when status is success' do - let(:status) { 'success' } - it 'has expected color' do expect(template.value_color).to eq '#4c1' end end context 'when status is failed' do - let(:status) { 'failed' } + before do + allow(badge).to receive(:status).and_return('failed') + end it 'has expected color' do expect(template.value_color).to eq '#e05d44' @@ -50,7 +50,9 @@ describe Gitlab::Badge::Build::Template do end context 'when status is running' do - let(:status) { 'running' } + before do + allow(badge).to receive(:status).and_return('running') + end it 'has expected color' do expect(template.value_color).to eq '#dfb317' @@ -58,7 +60,9 @@ describe Gitlab::Badge::Build::Template do end context 'when status is unknown' do - let(:status) { 'unknown' } + before do + allow(badge).to receive(:status).and_return('unknown') + end it 'has expected color' do expect(template.value_color).to eq '#9f9f9f' @@ -66,7 +70,9 @@ describe Gitlab::Badge::Build::Template do end context 'when status does not match any known statuses' do - let(:status) { 'invalid status' } + before do + allow(badge).to receive(:status).and_return('invalid') + end it 'has expected color' do expect(template.value_color).to eq '#9f9f9f' |