Class: SimpleCov::Formatter::JSONFormatter

Inherits:
Base
  • Object
show all
Defined in:
lib/simplecov/formatter/json_formatter.rb,
lib/simplecov/formatter/json_formatter/errors_formatter.rb,
lib/simplecov/formatter/json_formatter/result_hash_formatter.rb,
lib/simplecov/formatter/json_formatter/source_file_formatter.rb,
sig/simplecov.rbs

Overview

Writes coverage results as JSON to coverage/coverage.json.

Defined Under Namespace

Classes: ErrorsFormatter, ResultHashFormatter, SourceFileFormatter

Constant Summary collapse

FILENAME =

Returns:

  • ("coverage.json")
CoverageJSONWriter::FILENAME

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#displayable_output_path, #emit_status, #initialize, #output_message, #output_path, #relative_or_absolute_output_path, #stats_line

Constructor Details

This class inherits a constructor from SimpleCov::Formatter::Base

Class Method Details

.build_hash(result, include_source: SimpleCov.source_in_json) ⇒ Hash[Symbol, untyped]

The hash serialized to coverage.json ($schema, meta, total, coverage, groups, errors). include_source: defaults to SimpleCov.source_in_json; pass true to force the per-file source arrays regardless of the global setting.

Parameters:

  • result (SimpleCov::Result)
  • include_source: (Boolean) (defaults to: SimpleCov.source_in_json)

Returns:

  • (Hash[Symbol, untyped])


20
21
22
# File 'lib/simplecov/formatter/json_formatter.rb', line 20

def self.build_hash(result, include_source: SimpleCov.source_in_json)
  ResultHashFormatter.format(result, include_source: include_source)
end

Instance Method Details

#entry_point_filenameString

Returns:

  • (String)


35
36
37
# File 'lib/simplecov/formatter/json_formatter.rb', line 35

def entry_point_filename
  FILENAME
end

#format(result) ⇒ void

This method returns an undefined value.

Parameters:



24
25
26
27
# File 'lib/simplecov/formatter/json_formatter.rb', line 24

def format(result)
  CoverageJSONWriter.write(output_path, self.class.build_hash(result), result)
  emit_status(result)
end

#message_prefixString

Returns:

  • (String)


31
32
33
# File 'lib/simplecov/formatter/json_formatter.rb', line 31

def message_prefix
  "JSON "
end