Sha256: c94bfe7b9114386d70eb674d5b5f167823727d7299a1d103b74e1fae2c17adc6

Contents?: true

Size: 1003 Bytes

Versions: 4

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

module Undercover
  class Formatter
    def initialize(results)
      @results = results
    end

    def to_s
      return success unless @results.any?

      ([warnings_header] + formatted_warnings).join("\n")
    end

    private

    def formatted_warnings
      @results.map.with_index(1) do |res, idx|
        "🚨 #{idx}) node `#{res.node.name}` type: #{res.node.human_name},\n" +
          (' ' * pad_size) + "loc: #{res.file_path_with_lines}," \
                             " coverage: #{res.coverage_f * 100}%\n" +
          res.pretty_print
      end
    end

    def success
      "#{Rainbow('undercover').bold.green}: ✅ No coverage" \
        ' is missing in latest changes'
    end

    def warnings_header
      "#{Rainbow('undercover').bold.red}: " \
        '👮‍♂️ some methods have no test coverage! Please add specs for' \
        ' methods listed below'
    end

    def pad_size
      5 + (@results.size - 1).to_s.length
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
undercover-0.4.7 lib/undercover/formatter.rb
undercover-0.4.6 lib/undercover/formatter.rb
undercover-0.4.5 lib/undercover/formatter.rb
undercover-0.4.4 lib/undercover/formatter.rb