Module: SimpleCov::CLI::Serve::ReportPreparer

Defined in:
lib/simplecov/cli/serve/report_preparer.rb

Class Method Summary collapse

Class Method Details

.build_index(json_path, dir) ⇒ Object



22
23
24
25
26
# File 'lib/simplecov/cli/serve/report_preparer.rb', line 22

def self.build_index(json_path, dir)
  require_relative "../../formatter/html_formatter"
  Formatter::HTMLFormatter.new.format_from_json(json_path, dir)
  nil
end

.call(dir) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/simplecov/cli/serve/report_preparer.rb', line 9

def self.call(dir)
  index_path = File.join(dir, "index.html")
  json_path = File.join(dir, "coverage.json")
  return "#{dir} doesn't exist; run your test suite first" unless File.directory?(dir)
  return if File.file?(index_path)

  return "#{dir} has no index.html or coverage.json; run your test suite first" unless File.file?(json_path)

  build_index(json_path, dir)
rescue CoverageJSON::Error, SystemCallError => e
  "cannot build index.html from #{json_path}: #{e}"
end