Sha256: 62c6a222619b6c546dcefc9c508b3c2c9106425ad9d75352d0ec791b11ed7798

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

require 'simplecov'
require 'metric_fu'
require_relative 'external_client'
require_relative 'rcov_format_coverage'

class SimpleCov::Formatter::MetricFu

  def format(result)
    rcov_text = FormatLikeRCov.new(result).format
    client = MetricFu::RCovTestCoverageClient.new(coverage_file_path)
    client.post_results(rcov_text)
  end

  attr_writer :coverage_file_path

  def coverage_file_path
    @coverage_file_path || self.coverage_file_path = default_coverage_file_path
  end

  def default_coverage_file_path
    File.join(SimpleCov.root, 'coverage', 'rcov', output_file_name)
  end

  # TODO: Read in from legacy coverage/rcov/rcov.txt path, when set
  # write to date-specific report file, read from if present
  # e.g.
  #  MetricFu::Metric.get_metric(:rcov).run_options[:output_directory]
  #  or
  #  metric_directory = MetricFu::Io::FileSystem.scratch_directory('Ymd-coverage')
  #  MetricFu::Utility.mkdir_p(metric_directory, :verbose => false)
  # @note legacy file name is 'rcov.txt'
  #   going forward, the file name will be in a date-stamped
  #   format like for all other reported metrics.
  def output_file_name
    'rcov.txt'
  end

  class FormatLikeRCov
    def initialize(result)
      @result = result
    end

    def format
      content = "metric_fu shift the first line\n"
      @result.source_files.each do |source_file|
        content << "=" * 80
        content << "\n #{simple_file_name(source_file)}\n"
        content << "=" * 80
        content << "\n"
        source_file.lines.each do |line|
          content << (line.missed? ? '!!'  : '  ')
          content << " #{line.src.chomp}\n"
        end
        content << "\n"
      end
      content
    end

    def simple_file_name(source_file)
      source_file.filename.gsub(SimpleCov.root, '.')
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metric_fu-4.10.0 lib/metric_fu/metrics/rcov/simplecov_formatter.rb
metric_fu-4.9.0 lib/metric_fu/metrics/rcov/simplecov_formatter.rb