Change coverage badge rounding for other CI system consistency

This commit is contained in:
Jeff Stubler 2017-03-20 08:34:47 -05:00
parent 5b73e0eb35
commit 1fb4ed2155
5 changed files with 24 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
title: Show coverage to two decimal points in coverage badge
merge_request: 10083
author: Jeff Stubler
type: changed

View file

@ -23,7 +23,7 @@ module Gitlab
@coverage ||= raw_coverage @coverage ||= raw_coverage
return unless @coverage return unless @coverage
@coverage.to_i @coverage.to_f.round(2)
end end
def metadata def metadata

View file

@ -25,7 +25,7 @@ module Gitlab
end end
def value_text def value_text
@status ? "#{@status}%" : 'unknown' @status ? ("%.2f%%" % @status) : 'unknown'
end end
def key_width def key_width
@ -33,7 +33,7 @@ module Gitlab
end end
def value_width def value_width
@status ? 36 : 58 @status ? 54 : 58
end end
def value_color def value_color

View file

@ -18,7 +18,7 @@ feature 'test coverage badge' do
show_test_coverage_badge show_test_coverage_badge
expect_coverage_badge('95%') expect_coverage_badge('95.00%')
end end
scenario 'user requests coverage badge for specific job' do scenario 'user requests coverage badge for specific job' do
@ -30,7 +30,7 @@ feature 'test coverage badge' do
show_test_coverage_badge(job: 'coverage') show_test_coverage_badge(job: 'coverage')
expect_coverage_badge('85%') expect_coverage_badge('85.00%')
end end
scenario 'user requests coverage badge for pipeline without coverage' do scenario 'user requests coverage badge for pipeline without coverage' do

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Badge::Coverage::Template do describe Gitlab::Badge::Coverage::Template do
let(:badge) { double(entity: 'coverage', status: 90) } let(:badge) { double(entity: 'coverage', status: 90.00) }
let(:template) { described_class.new(badge) } let(:template) { described_class.new(badge) }
describe '#key_text' do describe '#key_text' do
@ -13,7 +13,17 @@ describe Gitlab::Badge::Coverage::Template do
describe '#value_text' do describe '#value_text' do
context 'when coverage is known' do context 'when coverage is known' do
it 'returns coverage percentage' do it 'returns coverage percentage' do
expect(template.value_text).to eq '90%' 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
end end
@ -37,7 +47,7 @@ describe Gitlab::Badge::Coverage::Template do
describe '#value_width' do describe '#value_width' do
context 'when coverage is known' do context 'when coverage is known' do
it 'is narrower when coverage is known' do it 'is narrower when coverage is known' do
expect(template.value_width).to eq 36 expect(template.value_width).to eq 54
end end
end end
@ -113,7 +123,7 @@ describe Gitlab::Badge::Coverage::Template do
describe '#width' do describe '#width' do
context 'when coverage is known' do context 'when coverage is known' do
it 'returns the key width plus value width' do it 'returns the key width plus value width' do
expect(template.width).to eq 98 expect(template.width).to eq 116
end end
end end