Class: CoverallsMulti::Formatter::Simplecov

Inherits:
Object
  • Object
show all
Defined in:
lib/coveralls-multi/formatters/simplecov.rb

Overview

formats SimpleCov coverage results files before merge + push to Coveralls

Instance Method Summary collapse

Instance Method Details

#format_short_filename(filename) ⇒ Object

helper to grab the filename relative to the repo root



8
9
10
11
# File 'lib/coveralls-multi/formatters/simplecov.rb', line 8

def format_short_filename(filename)
  filename = filename.gsub(CoverallsMulti::Config.root, '.').gsub(/^\.\//, '') if CoverallsMulti::Config.root
  filename
end

#run(file_path) ⇒ Object

get relevant data from the Ruby coverage report & format it



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/coveralls-multi/formatters/simplecov.rb', line 14

def run(file_path)
  file = CoverallsMulti::Formatter.parse_json(file_path)

  source_files = []
  begin
    file.keys.each do |test_suite_key|
      file[test_suite_key]['coverage'].each do |filename, coverage|
        properties = {}

        properties['source'] = File.open(filename, 'rb:utf-8').read
        properties['name'] = format_short_filename(filename)
        properties['coverage'] = coverage

        source_files << properties
      end
    end
  rescue StandardError => e
    puts "[CoverallsMulti] There was a problem formatting the simplecov report at #{file_path}."
    puts '[CoverallsMulti] Make sure the file exists.'
    raise e
  end

  source_files
end