class CoverallsMulti::Formatter::Simplecov

formats SimpleCov coverage results files before merge + push to Coveralls

Public Instance Methods

format_short_filename(filename) click to toggle source

helper to grab the filename relative to the repo root

# 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) click to toggle source

get relevant data from the Ruby coverage report & format it

# 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