Sha256: fa5ccab1e072c7a5580483c9a400b2085f0d912d5a594ac2778af9ba55071ec4

Contents?: true

Size: 1.55 KB

Versions: 10

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module SimpleCov
  module ExitCodes
    class MinimumCoverageByFileCheck
      def initialize(result, minimum_coverage_by_file)
        @result = result
        @minimum_coverage_by_file = minimum_coverage_by_file
      end

      def failing?
        minimum_violations.any?
      end

      def report
        minimum_violations.each do |violation|
          $stderr.printf(
            "%<criterion>s coverage by file (%<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_by_file

      def minimum_violations
        @minimum_violations ||=
          compute_minimum_coverage_data.select do |achieved|
            achieved.fetch(:actual) < achieved.fetch(:minimum_expected)
          end
      end

      def compute_minimum_coverage_data
        minimum_coverage_by_file.flat_map do |criterion, expected_percent|
          result.coverage_statistics_by_file.fetch(criterion).map do |actual_coverage|
            {
              criterion: criterion,
              minimum_expected: expected_percent,
              actual: SimpleCov.round_coverage(actual_coverage.percent)
            }
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 9 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
strongmind-simplecov-0.23.0 lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
simplecov-0.22.0 lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/simplecov-0.21.2/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
simplecov-0.21.2 lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
simplecov-0.21.1 lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb