Class: SimpleCov::Result
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Forwardable
|
|
| Inherits: | Object |
| Defined in: | lib/simplecov/result.rb, lib/simplecov/result/missing_source_files_reporter.rb, lib/simplecov/result/source_file_builder.rb |
Overview
A simplecov code coverage result, initialized from the Hash Ruby's built-in coverage library generates (Coverage.result).
Class Method Summary
-
.from_hash(hash)
Loads a #to_hash dump.
-
.new(original_result, command_name: nil, created_at: nil, not_loaded_files: Set.new, filter_config: FilterConfig.new) ⇒ Result
constructor
Initialize a new
Resultfrom givenCoverage.result(a Hash of filenames each containing an array of coverage data).
Instance Attribute Summary
-
#command_name
rw
The command name that launched this result.
-
#command_name=(value)
rw
Explicitly set the command name that was used for this coverage result.
-
#created_at
rw
Defines when this result has been created.
-
#created_at=(value)
rw
Explicitly set the Time this result has been created.
-
#files
(also: #source_files)
readonly
Returns all files that are applicable to this result (sans filters!) as instances of
SourceFile. -
#original_result
readonly
Returns the original
Coverage.resultused for this instance ofResult -
#source_files
readonly
Alias for #files.
Instance Method Summary
-
#coverage_for(path)
Returns the
line:/branch:/method:coverage_statistics hash for the given file path, or nil if no matching source file is in this result. -
#filenames
Returns all filenames for source files contained in this result.
-
#format!
Applies the configured
SimpleCov.formatteron this result. -
#groups
Returns a Hash of groups for this result.
-
#source_file_for(path)
Returns the
SourceFilefor the given path, or nil if no matching file is in this result. -
#to_hash
Returns a hash representation of this
Resultthat can be used for marshalling it into JSON. -
#apply_cover_filters!(cover_filters)
private
When any
covermatcher is configured, restrict@filesto source files matching at least one of them. -
#apply_filters!(filters)
private
Applies the given filter chain to
@files, dropping each source file that any filter matches. - #coverage private
- #warn_about_missing_source_files(missing, input_size) private
Constructor Details
.new(original_result, command_name: nil, created_at: nil, not_loaded_files: Set.new, filter_config: FilterConfig.new) ⇒ Result
Initialize a new Result from given Coverage.result (a Hash of filenames each containing an array of
coverage data).
filter_config defaults to the ::SimpleCov singleton's filter / group
configuration so existing call sites are unchanged. Pass a custom
Result::FilterConfig to opt out — useful for tests that build synthetic Results
and don't want the project's filters or groups applied.
# File 'lib/simplecov/result.rb', line 57
def initialize(original_result, command_name: nil, created_at: nil, not_loaded_files: Set.new, filter_config: FilterConfig.new) @original_result = original_result.freeze @command_name = command_name @created_at = created_at @groups_config = filter_config.groups builder = SourceFileBuilder.new(original_result, not_loaded_files: not_loaded_files) @files = builder.call warn_about_missing_source_files(builder.missing_source_files, original_result.size) apply_cover_filters!(filter_config.cover_filters) apply_filters!(filter_config.filters) end
Class Method Details
.from_hash(hash)
Loads a #to_hash dump
# File 'lib/simplecov/result.rb', line 130
def self.from_hash(hash) hash.map do |command_name, data| new(data.fetch("coverage"), command_name: command_name, created_at: Time.at(data["timestamp"])) end end
Instance Attribute Details
#command_name (rw)
The command name that launched this result.
Delegated to SimpleCov.command_name if not set manually
# File 'lib/simplecov/result.rb', line 115
def command_name @command_name ||= SimpleCov.command_name end
#command_name=(value) (rw)
Explicitly set the command name that was used for this coverage result. Defaults to SimpleCov.command_name
# File 'lib/simplecov/result.rb', line 25
attr_writer :command_name
#created_at (rw)
Defines when this result has been created. Defaults to Time.now
# File 'lib/simplecov/result.rb', line 109
def created_at @created_at ||= Time.now end
#created_at=(value) (rw)
Explicitly set the Time this result has been created
# File 'lib/simplecov/result.rb', line 23
attr_writer :created_at
#files (readonly) Also known as: #source_files
Returns all files that are applicable to this result (sans filters!) as instances of
SourceFile. Aliased as :source_files
# File 'lib/simplecov/result.rb', line 20
attr_reader :files
#original_result (readonly)
Returns the original Coverage.result used for this instance of Result
# File 'lib/simplecov/result.rb', line 17
attr_reader :original_result
#source_files (readonly)
Alias for #files.
# File 'lib/simplecov/result.rb', line 21
alias source_files files
Instance Method Details
#apply_cover_filters!(cover_filters) (private)
When any cover matcher is configured, restrict @files to source
files matching at least one of them. With no cover matchers configured
this is a no-op, preserving the historical "everything required, then
filtered" universe.
#apply_filters!(filters) (private)
Applies the given filter chain to @files, dropping each source
file that any filter matches.
#coverage (private)
[ GitHub ]# File 'lib/simplecov/result.rb', line 148
def coverage original_result.slice(*filenames) end
#coverage_for(path)
Returns the line:/branch:/method: coverage_statistics hash for the
given file path, or nil if no matching source file is in this
result. See #source_file_for for path resolution.
# File 'lib/simplecov/result.rb', line 87
def coverage_for(path) source_file_for(path)&.coverage_statistics end
#filenames
Returns all filenames for source files contained in this result
# File 'lib/simplecov/result.rb', line 71
def filenames files.map(&:filename) end
#format!
Applies the configured SimpleCov.formatter on this result. Returns
nil if formatting has been opted out of (SimpleCov.formatter false
/ SimpleCov.formatters []) — the cheap path for non-final
processes in a parallel CI run, which only need their
.resultset.json on disk. See #964.
#groups
Returns a Hash of groups for this result. Define groups using SimpleCov.group 'Models', 'app/models'
#source_file_for(path)
Returns the SourceFile for the given path, or nil if no
matching file is in this result. The path is resolved against
SimpleCov.root, so callers can pass either an absolute path or a
project-relative one.
#to_hash
Returns a hash representation of this Result that can be used for marshalling it into JSON
# File 'lib/simplecov/result.rb', line 120
def to_hash { command_name => { "coverage" => coverage, "timestamp" => created_at.to_i } } end
#warn_about_missing_source_files(missing, input_size) (private)
[ GitHub ]# File 'lib/simplecov/result.rb', line 138
def warn_about_missing_source_files(missing, input_size) return if missing.empty? MissingSourceFilesReporter.new( missing, input_size: input_size, every_entry_dropped: @files.empty? && missing.size == input_size ).warn! end