|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "helper" |
| 4 | + |
| 5 | +RSpec.describe SimpleCov::ExitCodes::MaximumCoverageDropCheck do |
| 6 | + let(:result) do |
| 7 | + instance_double(SimpleCov::Result, coverage_statistics: stats) |
| 8 | + end |
| 9 | + let(:stats) do |
| 10 | + { |
| 11 | + line: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2), |
| 12 | + branch: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2) |
| 13 | + } |
| 14 | + end |
| 15 | + let(:last_run) do |
| 16 | + { |
| 17 | + result: last_coverage |
| 18 | + } |
| 19 | + end |
| 20 | + let(:last_coverage) { {line: 80.0, branch: 80.0} } |
| 21 | + let(:maximum_coverage_drop) { {line: 0, branch: 0} } |
| 22 | + subject { described_class.new(result, maximum_coverage_drop) } |
| 23 | + |
| 24 | + before :each do |
| 25 | + expect(SimpleCov::LastRun).to receive(:read).and_return(last_run) |
| 26 | + end |
| 27 | + |
| 28 | + context "we're at the same coverage" do |
| 29 | + it { is_expected.not_to be_failing } |
| 30 | + end |
| 31 | + |
| 32 | + context "more coverage drop allowed" do |
| 33 | + let(:maximum_coverage_drop) { {line: 10, branch: 10} } |
| 34 | + |
| 35 | + it { is_expected.not_to be_failing } |
| 36 | + end |
| 37 | + |
| 38 | + context "last coverage lower then new coverage" do |
| 39 | + let(:last_coverage) { {line: 70.0, branch: 70.0} } |
| 40 | + |
| 41 | + it { is_expected.not_to be_failing } |
| 42 | + end |
| 43 | + |
| 44 | + context "last coverage higher than new coverage" do |
| 45 | + let(:last_coverage) { {line: 80.01, branch: 80.01} } |
| 46 | + |
| 47 | + it { is_expected.to be_failing } |
| 48 | + |
| 49 | + context "but allowed drop is within range" do |
| 50 | + let(:maximum_coverage_drop) { {line: 0.01, branch: 0.01} } |
| 51 | + |
| 52 | + it { is_expected.not_to be_failing } |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + context "one coverage lower than maximum drop" do |
| 57 | + let(:last_coverage) { {line: 80.01, branch: 70.0} } |
| 58 | + |
| 59 | + it { is_expected.to be_failing } |
| 60 | + |
| 61 | + context "but allowed drop is within range" do |
| 62 | + let(:maximum_coverage_drop) { {line: 0.01} } |
| 63 | + |
| 64 | + it { is_expected.not_to be_failing } |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + context "coverage expectation for a coverage that wasn't previously present" do |
| 69 | + let(:last_coverage) { {line: 80.0} } |
| 70 | + let(:maximum_coverage_drop) { {line: 0, branch: 0} } |
| 71 | + |
| 72 | + it { is_expected.not_to be_failing } |
| 73 | + end |
| 74 | + |
| 75 | + context "no last run coverage information" do |
| 76 | + let(:last_run) { nil } |
| 77 | + |
| 78 | + it { is_expected.not_to be_failing } |
| 79 | + end |
| 80 | + |
| 81 | + context "old last_run.json format" do |
| 82 | + let(:last_run) do |
| 83 | + { |
| 84 | + # this format only considers line coverage |
| 85 | + result: {covered_percent: 80.0} |
| 86 | + } |
| 87 | + end |
| 88 | + |
| 89 | + it { is_expected.not_to be_failing } |
| 90 | + end |
| 91 | +end |
0 commit comments