diff options
Diffstat (limited to 'spec/lib/gitlab/ci/reports/coverage_reports_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/reports/coverage_reports_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/reports/coverage_reports_spec.rb b/spec/lib/gitlab/ci/reports/coverage_reports_spec.rb new file mode 100644 index 00000000000..7cf43ceab32 --- /dev/null +++ b/spec/lib/gitlab/ci/reports/coverage_reports_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Reports::CoverageReports do + let(:coverage_report) { described_class.new } + + it { expect(coverage_report.files).to eq({}) } + + describe '#pick' do + before do + coverage_report.add_file('app.rb', { 1 => 0, 2 => 1 }) + coverage_report.add_file('routes.rb', { 3 => 1, 4 => 0 }) + end + + it 'returns only picked files while ignoring nonexistent ones' do + expect(coverage_report.pick(['routes.rb', 'nonexistent.txt'])).to eq({ + files: { 'routes.rb' => { 3 => 1, 4 => 0 } } + }) + end + end + + describe '#add_file' do + context 'when providing two individual files' do + before do + coverage_report.add_file('app.rb', { 1 => 0, 2 => 1 }) + coverage_report.add_file('routes.rb', { 3 => 1, 4 => 0 }) + end + + it 'initializes a new test suite and returns it' do + expect(coverage_report.files).to eq({ + 'app.rb' => { 1 => 0, 2 => 1 }, + 'routes.rb' => { 3 => 1, 4 => 0 } + }) + end + end + + context 'when providing the same files twice' do + context 'with different line coverage' do + before do + coverage_report.add_file('admin.rb', { 1 => 0, 2 => 1 }) + coverage_report.add_file('admin.rb', { 3 => 1, 4 => 0 }) + end + + it 'initializes a new test suite and returns it' do + expect(coverage_report.files).to eq({ + 'admin.rb' => { 1 => 0, 2 => 1, 3 => 1, 4 => 0 } + }) + end + end + + context 'with identical line coverage' do + before do + coverage_report.add_file('projects.rb', { 1 => 0, 2 => 1 }) + coverage_report.add_file('projects.rb', { 1 => 0, 2 => 1 }) + end + + it 'initializes a new test suite and returns it' do + expect(coverage_report.files).to eq({ + 'projects.rb' => { 1 => 0, 2 => 2 } + }) + end + end + end + end +end |