Sha256: 0678c170a12e4eabdd31e5df3f19b6fc83dafe1e34848d1884c930c72e263a5e

Contents?: true

Size: 1.4 KB

Versions: 13

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module SimpleCov
  module ExitCodes
    class MinimumOverallCoverageCheck
      def initialize(result, minimum_coverage)
        @result = result
        @minimum_coverage = minimum_coverage
      end

      def failing?
        minimum_violations.any?
      end

      def report
        minimum_violations.each do |violation|
          $stderr.printf(
            "%<criterion>s coverage (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%).\n",
            covered: SimpleCov.round_coverage(violation.fetch(:actual)),
            minimum_coverage: violation.fetch(:minimum_expected),
            criterion: violation.fetch(:criterion).capitalize
          )
        end
      end

      def exit_code
        SimpleCov::ExitCodes::MINIMUM_COVERAGE
      end

    private

      attr_reader :result, :minimum_coverage

      def minimum_violations
        @minimum_violations ||= calculate_minimum_violations
      end

      def calculate_minimum_violations
        coverage_achieved = minimum_coverage.map do |criterion, percent|
          {
            criterion: criterion,
            minimum_expected: percent,
            actual: result.coverage_statistics.fetch(criterion).percent
          }
        end

        coverage_achieved.select do |achieved|
          achieved.fetch(:actual) < achieved.fetch(:minimum_expected)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 7 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
strongmind-simplecov-0.23.0 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.22.0 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/simplecov-0.21.2/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.21.2 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.21.1 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.21.0 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.20.0 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.19.1 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/simplecov-0.19.0/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
simplecov-0.19.0 lib/simplecov/exit_codes/minimum_overall_coverage_check.rb