-
# frozen_string_literal: true
-
-
1
require 'spec_helper'
-
-
1
describe SimpleCovSmallBadge::Formatter do
-
1
include TestSimpleCovSmallBadge::Mocks
-
-
1
describe '#format' do
-
1
context 'bad result' do
-
1
it do
-
1
allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 90)
-
1
mock_repo_badge_image(cov: '50%', state: 'bad')
-
1
result = mock_result(50)
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'good result' do
-
1
it do
-
1
allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 100)
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: '100%')
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: '100%', mock: image_mock)
-
1
result = mock_result(100, 'library' => mock_result_group(100))
-
1
expect(subject.format(result)).to be_truthy
-
end
-
-
1
it do
-
1
allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 90)
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: '90%')
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: '90%', mock: image_mock)
-
1
result = mock_result(90, 'library' => mock_result_group(90))
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'bad result' do
-
1
it do
-
1
allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 91)
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: '90%', state: 'bad')
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: '90%', state: 'bad', mock: image_mock)
-
1
result = mock_result(90, 'library' => mock_result_group(90))
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'unknown result' do
-
1
it do
-
1
allow(SimpleCov).to receive(:minimum_coverage).and_return({})
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: '90%', state: 'unknown')
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: '90%', state: 'unknown', mock: image_mock)
-
1
result = mock_result(90, 'library' => mock_result_group(90))
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'mixed result' do
-
1
it do
-
1
allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 90)
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: '89%', state: 'bad')
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: '90%', state: 'good', mock: image_mock)
-
1
result = mock_result(89, 'library' => mock_result_group(90))
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'with branch coverage' do
-
1
before do
-
7
SimpleCov.enable_coverage :branch
-
7
SimpleCov.primary_coverage :branch
-
7
allow(SimpleCov).to receive(:minimum_coverage)
-
.and_return(minimum_coverage)
-
end
-
-
1
after do
-
7
SimpleCov.clear_coverage_criteria
-
7
SimpleCov.enable_coverage :line
-
7
SimpleCov.primary_coverage :line
-
end
-
-
1
context 'when coverage is lower than required' do
-
2
let(:minimum_coverage) { { branch: 90, line: 100 } }
-
2
let(:coverage) { 50 }
-
2
let(:expected_state) { 'bad' }
-
-
1
it 'is bad' do
-
1
mock_repo_badge_image(cov: "#{coverage}%", state: expected_state)
-
1
result = mock_result(coverage)
-
1
subject.format(result)
-
end
-
end
-
-
1
context 'when coverage is lower than required with groups' do
-
2
let(:minimum_coverage) { { branch: 91, line: 100 } }
-
2
let(:coverage) { 90 }
-
2
let(:expected_state) { 'bad' }
-
-
1
it 'is bad' do
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: "#{coverage}%",
-
state: expected_state)
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: "#{coverage}%", state: expected_state,
-
mock: image_mock)
-
1
result = mock_result(coverage,
-
'library' => mock_result_group(coverage))
-
1
subject.format(result)
-
end
-
end
-
-
1
context 'when coverage is greater than or equal to that required' do
-
2
let(:minimum_coverage) { { branch: 100, line: 10 } }
-
2
let(:coverage) { 100 }
-
2
let(:expected_state) { 'good' }
-
-
1
it 'is good' do
-
1
mock_repo_badge_image(cov: '100%', state: expected_state)
-
1
result = mock_result(coverage)
-
1
subject.format(result)
-
end
-
end
-
-
1
context 'when coverage is greater than or equal to that required with groups' do
-
2
let(:minimum_coverage) { { branch: 100, line: 10 } }
-
2
let(:coverage) { 100 }
-
1
let(:expected_state) { 'good' }
-
-
1
it 'is good' do
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: "#{coverage}%")
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: "#{coverage}%", mock: image_mock)
-
1
result = mock_result(coverage, 'library' => mock_result_group(coverage))
-
1
subject.format(result)
-
end
-
end
-
-
1
context 'when minimum coverage is not set' do
-
2
let(:minimum_coverage) { {} }
-
2
let(:coverage) { 90 }
-
2
let(:expected_state) { 'unknown' }
-
-
1
it 'is unknown' do
-
1
mock_repo_badge_image(cov: "#{coverage}%",
-
state: expected_state)
-
1
result = mock_result(coverage)
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'when minimum coverage is not set with groups' do
-
2
let(:minimum_coverage) { {} }
-
2
let(:coverage) { 90 }
-
2
let(:expected_state) { 'unknown' }
-
-
1
it 'is unknown' do
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: "#{coverage}%",
-
state: expected_state)
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: "#{coverage}%", state: expected_state,
-
mock: image_mock)
-
1
result = mock_result(coverage,
-
'library' => mock_result_group(coverage))
-
1
expect(subject.format(result)).to be_truthy
-
end
-
end
-
-
1
context 'when global coverage is lower but group coverage is as required' do
-
2
let(:minimum_coverage) { { branch: 90, line: 10 } }
-
2
let(:global_coverage) { 89 }
-
2
let(:group_coverage) { 90 }
-
2
let(:global_state) { 'bad' }
-
2
let(:group_state) { 'good' }
-
-
1
it 'is mixed' do
-
1
image_mock = mock_repo_badge_image(title: 'total', name: 'total',
-
cov: "#{global_coverage}%",
-
state: global_state)
-
1
mock_repo_badge_image(title: 'library', name: 'library',
-
cov: "#{group_coverage}%",
-
state: group_state,
-
mock: image_mock)
-
1
result = mock_result(global_coverage,
-
'library' => mock_result_group(group_coverage))
-
1
subject.format(result)
-
end
-
end
-
end
-
end
-
end