Sha256: b620ca890cfb3eb5fefa9a07d2df87a734a11b9442cc8ce1a631f12117842518

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 KB

Contents

MetricFu.lib_require { "utility" }
MetricFu.lib_require { "calculate" }
MetricFu.data_structures_require { "line_numbers" }
require_relative "rcov_format_coverage"
require_relative "rcov_line"
require_relative "external_client"

module MetricFu
  class RcovGenerator < MetricFu::Generator
    def self.metric
      :rcov
    end

    def emit
      if run_rcov?
        mf_debug "** Running the specs/tests in the [#{options[:environment]}] environment"
        mf_debug "** #{command}"
        `#{command}`
      end
    end

    def command
      @command ||= default_command
    end

    def command=(command)
      @command = command
    end

    def reset_output_location
      MetricFu::Utility.rm_rf(metric_directory, verbose: false)
      MetricFu::Utility.mkdir_p(metric_directory)
    end

    def default_command
      require "rake"
      reset_output_location
      test_files = FileList[*options[:test_files]].join(" ")
      rcov_opts = options[:rcov_opts].join(" ")
      %(RAILS_ENV=#{options[:environment]} rcov #{test_files} #{rcov_opts} >> #{default_output_file})
    end

    def analyze
      rcov_text = load_output
      formatter = MetricFu::RCovFormatCoverage.new(rcov_text)
      @rcov = formatter.to_h
    end

    def to_h
      {
        rcov: @rcov
      }
    end

    private

    # We never run rcov anymore
    def run_rcov?
      false
    end

    def load_output
      MetricFu::RCovTestCoverageClient.new(output_file).load
    end

    def output_file
      options.fetch(:external)
    end

    # Only used if run_rcov? is true
    def default_output_file
      output_file || File.join(metric_directory, "rcov.txt")
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
metric_fu-4.13.0 lib/metric_fu/metrics/rcov/generator.rb
fastruby-metric_fu-5.0.0 lib/metric_fu/metrics/rcov/generator.rb
code_metric_fu-4.14.4 lib/metric_fu/metrics/rcov/generator.rb
code_metric_fu-4.14.3 lib/metric_fu/metrics/rcov/generator.rb
code_metric_fu-4.14.2 lib/metric_fu/metrics/rcov/generator.rb
code_metric_fu-4.14.1 lib/metric_fu/metrics/rcov/generator.rb
code_metric_fu-4.14.0 lib/metric_fu/metrics/rcov/generator.rb
metric_fu-4.12.0 lib/metric_fu/metrics/rcov/generator.rb
metric_fu-4.11.4 lib/metric_fu/metrics/rcov/generator.rb