2020-08-25 12:04:30 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-09-01 21:10:21 +00:00
|
|
|
RSpec.describe Ci::PipelineArtifacts::CodeCoveragePresenter do
|
2020-08-25 12:04:30 +00:00
|
|
|
let(:pipeline_artifact) { create(:ci_pipeline_artifact, :with_code_coverage_with_multiple_files) }
|
2020-09-01 21:10:21 +00:00
|
|
|
|
|
|
|
subject(:presenter) { described_class.new(pipeline_artifact) }
|
2020-08-25 12:04:30 +00:00
|
|
|
|
|
|
|
describe '#for_files' do
|
2020-09-01 21:10:21 +00:00
|
|
|
subject { presenter.for_files(filenames) }
|
2020-08-25 12:04:30 +00:00
|
|
|
|
|
|
|
context 'when code coverage has data' do
|
|
|
|
context 'when filenames is empty' do
|
|
|
|
let(:filenames) { %w() }
|
|
|
|
|
|
|
|
it 'returns hash without coverage' do
|
|
|
|
expect(subject).to match(files: {})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when filenames do not match code coverage data' do
|
|
|
|
let(:filenames) { %w(demo.rb) }
|
|
|
|
|
|
|
|
it 'returns hash without coverage' do
|
|
|
|
expect(subject).to match(files: {})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when filenames matches code coverage data' do
|
|
|
|
context 'when asking for one filename' do
|
|
|
|
let(:filenames) { %w(file_a.rb) }
|
|
|
|
|
|
|
|
it 'returns coverage for the given filename' do
|
|
|
|
expect(subject).to match(files: { "file_a.rb" => { "1" => 1, "2" => 1, "3" => 1 } })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when asking for multiple filenames' do
|
|
|
|
let(:filenames) { %w(file_a.rb file_b.rb) }
|
|
|
|
|
|
|
|
it 'returns coverage for a the given filenames' do
|
|
|
|
expect(subject).to match(
|
|
|
|
files: {
|
|
|
|
"file_a.rb" => {
|
|
|
|
"1" => 1,
|
|
|
|
"2" => 1,
|
|
|
|
"3" => 1
|
|
|
|
},
|
|
|
|
"file_b.rb" => {
|
|
|
|
"1" => 0,
|
|
|
|
"2" => 0,
|
|
|
|
"3" => 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|