Class: Cyclid::API::Plugins::Simplecov

Inherits:
Action
  • Object
show all
Defined in:
app/cyclid/plugins/action/simplecov.rb

Overview

Simplecov coverage reader plugin

Instance Method Summary collapse

Methods inherited from Action

human_name, #prepare

Methods inherited from Base

config?, config_schema, default_config, get_config, human_name, register_plugin, set_config, update_config

Constructor Details

#initialize(args = {}) ⇒ Simplecov

Returns a new instance of Simplecov.



24
25
26
27
28
29
30
31
# File 'app/cyclid/plugins/action/simplecov.rb', line 24

def initialize(args = {})
  args.symbolize_keys!

  # There must be the path to the coverage report..
  raise 'a simplecov action requires a path' unless args.include? :path

  @path = args[:path]
end

Instance Method Details

#perform(log) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/cyclid/plugins/action/simplecov.rb', line 33

def perform(log)
  # Retrieve the Simplecov JSON report
  report = StringIO.new
  @transport.download(report, @path ** @ctx)

  # Parse the report and extract the total coverage percentage;
  # Simplecov can produce oddly specific coverage metrics, so round it
  # to only 2 decimal points...
  coverage = JSON.parse(report.string)
  covered_percent = coverage['metrics']['covered_percent'].round(2)

  log.write "Simplecov coverage is #{covered_percent}%\n"
  @ctx[:simplecov_coverage] = "#{covered_percent}%"

  return [true, 0]
rescue StandardError => ex
  log.write "Failed to read Simplecov coverage report: #{ex}"

  return [false, 0]
end