diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-29 08:55:49 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-29 09:01:24 +0200 |
commit | d6097ca402d78fb23383fee2afc91e7bafc604c3 (patch) | |
tree | e3c54b32d5423429992e6f2f51d79ebddaea8118 | |
parent | 4cd1b9f4d82efe3ffe810dabf6929a749c36c1bf (diff) | |
download | gitlab-ce-refactor/project-badges-interface.tar.gz |
Extend specs for build badgerefactor/project-badges-interface
-rw-r--r-- | spec/lib/gitlab/badge/build_spec.rb | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/spec/lib/gitlab/badge/build_spec.rb b/spec/lib/gitlab/badge/build_spec.rb index e835de5e07d..b78c2b6224f 100644 --- a/spec/lib/gitlab/badge/build_spec.rb +++ b/spec/lib/gitlab/badge/build_spec.rb @@ -3,31 +3,70 @@ require 'spec_helper' describe Gitlab::Badge::Build do let(:project) { create(:project) } let(:sha) { project.commit.sha } - let(:ci_commit) { create(:ci_commit, project: project, sha: sha) } let(:badge) { described_class.new(project, 'master') } - let!(:build) { create(:ci_build, commit: ci_commit) } - describe '#type' do subject { badge.type } it { is_expected.to eq 'image/svg+xml' } end - context 'build success' do - before { build.success! } + context 'build exists' do + let(:ci_commit) { create(:ci_commit, project: project, sha: sha) } + let!(:build) { create(:ci_build, commit: ci_commit) } + + + context 'build success' do + before { build.success! } + + describe '#to_s' do + subject { badge.to_s } + it { is_expected.to eq 'build-success' } + end + + describe '#data' do + let(:data) { badge.data } + + it 'contains infromation about success' do + expect(status_node(data, 'success')).to be_truthy + end + end + end + + context 'build failed' do + before { build.drop! } + describe '#to_s' do + subject { badge.to_s } + it { is_expected.to eq 'build-failed' } + end + + describe '#data' do + let(:data) { badge.data } + + it 'contains infromation about failure' do + expect(status_node(data, 'failed')).to be_truthy + end + end + end + end + + context 'build does not exist' do describe '#to_s' do subject { badge.to_s } - it { is_expected.to eq 'build-success' } + it { is_expected.to eq 'build-unknown' } end describe '#data' do let(:data) { badge.data } - let(:xml) { Nokogiri::XML.parse(data) } - it 'contains infromation about success' do - expect(xml.at(%Q{text:contains("success")})).to be_truthy + it 'contains infromation about unknown build' do + expect(status_node(data, 'unknown')).to be_truthy end end end + + def status_node(data, status) + xml = Nokogiri::XML.parse(data) + xml.at(%Q{text:contains("#{status}")}) + end end |