BigW Consortium Gitlab

Commit 1fb4ed21 by Jeff Stubler

Change coverage badge rounding for other CI system consistency

parent 5b73e0eb
---
title: Show coverage to two decimal points in coverage badge
merge_request: 10083
author: Jeff Stubler
type: changed
......@@ -23,7 +23,7 @@ module Gitlab
@coverage ||= raw_coverage
return unless @coverage
@coverage.to_i
@coverage.to_f.round(2)
end
def metadata
......
......@@ -25,7 +25,7 @@ module Gitlab
end
def value_text
@status ? "#{@status}%" : 'unknown'
@status ? ("%.2f%%" % @status) : 'unknown'
end
def key_width
......@@ -33,7 +33,7 @@ module Gitlab
end
def value_width
@status ? 36 : 58
@status ? 54 : 58
end
def value_color
......
......@@ -18,7 +18,7 @@ feature 'test coverage badge' do
show_test_coverage_badge
expect_coverage_badge('95%')
expect_coverage_badge('95.00%')
end
scenario 'user requests coverage badge for specific job' do
......@@ -30,7 +30,7 @@ feature 'test coverage badge' do
show_test_coverage_badge(job: 'coverage')
expect_coverage_badge('85%')
expect_coverage_badge('85.00%')
end
scenario 'user requests coverage badge for pipeline without coverage' do
......
require 'spec_helper'
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) }
describe '#key_text' do
......@@ -13,7 +13,17 @@ describe Gitlab::Badge::Coverage::Template do
describe '#value_text' do
context 'when coverage is known' 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
......@@ -37,7 +47,7 @@ describe Gitlab::Badge::Coverage::Template do
describe '#value_width' do
context '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
......@@ -113,7 +123,7 @@ describe Gitlab::Badge::Coverage::Template do
describe '#width' do
context 'when coverage is known' do
it 'returns the key width plus value width' do
expect(template.width).to eq 98
expect(template.width).to eq 116
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment