class SleepingKingStudios::Tasks::Apps::Ci::SimpleCovTask

Defines a Thor task for aggregating SimpleCov coverage results across applications.

Constants

RESULTS_STRUCT

Public Class Methods

configure_simplecov!() click to toggle source
# File lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb, line 19
def self.configure_simplecov!
  require 'simplecov'
  require 'simplecov-json'

  ::SimpleCov.configure do
    command_name "#{command_name}:#{ENV['APP_NAME']}" if ENV['APP_NAME']

    self.formatter =
      ::SimpleCov::Formatter::MultiFormatter.new(
        [formatter, ::SimpleCov::Formatter::JSONFormatter]
      ) # end formatter
  end # configure
end
description() click to toggle source
# File lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb, line 33
def self.description
  'Aggregates the SimpleCov results for all applications.'
end
task_name() click to toggle source
# File lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb, line 37
def self.task_name
  'simplecov'
end

Public Instance Methods

call(_application = nil) click to toggle source
# File lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb, line 41
def call _application = nil
  results = load_report :report => File.join('coverage', 'coverage.json')
  results = convert_results_to_object(results)

  SleepingKingStudios::Tasks::Ci::SimpleCovResults.new(results)
end

Private Instance Methods

convert_results_to_object(hsh) click to toggle source
# File lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb, line 59
def convert_results_to_object hsh
  RESULTS_STRUCT.new(
    hsh.fetch('covered_lines', 0),
    hsh.fetch('covered_percent', 0.0),
    hsh.fetch('total_lines', 0) - hsh.fetch('covered_lines', 0),
    hsh.fetch('total_lines', 0)
  ) # end object
end
load_report(report: raw = File.read report) click to toggle source
# File lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb, line 50
def load_report report:
  raw  = File.read report
  json = JSON.parse raw

  json['metrics']
rescue
  {}
end