Module: SimpleCov::Configuration
- Included in:
- SimpleCov
- Defined in:
- lib/simplecov/configuration.rb,
lib/simplecov/configuration/groups.rb,
lib/simplecov/configuration/filters.rb,
lib/simplecov/configuration/history.rb,
lib/simplecov/configuration/merging.rb,
lib/simplecov/configuration/baseline.rb,
lib/simplecov/configuration/coverage.rb,
lib/simplecov/configuration/formatting.rb,
lib/simplecov/configuration/production.rb,
lib/simplecov/configuration/thresholds.rb,
lib/simplecov/configuration/missed_caps.rb,
lib/simplecov/configuration/deprecations.rb,
lib/simplecov/configuration/eval_coverage.rb,
lib/simplecov/configuration/test_tracking.rb,
lib/simplecov/configuration/view_coverage.rb,
lib/simplecov/configuration/ignored_entries.rb,
lib/simplecov/configuration/coverage_criteria.rb,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs
Defined Under Namespace
Classes: CoverageCriterion
Constant Summary collapse
- DROP_BASELINES =
%i[last_run median branch].freeze
- COVERAGE_THRESHOLD_OPTIONS =
%i[minimum maximum exact maximum_drop ignore minimum_per_file maximum_missed maximum_missed_per_file].freeze
- BUILT_IN_FORMATS =
{ html: :HTMLFormatter, json: :JSONFormatter, simple: :SimpleFormatter, baseline: :BaselineFormatter }.freeze
- LAZY_FORMAT_REQUIRES =
{html: "../../simplecov-html"}.freeze
- DEPRECATION_MODES =
Deprecation::MODES
- TRACK_TESTS_GRANULARITIES =
%i[test file].freeze
- DEFAULT_VIEW_GLOBS =
%w[app/views/**/*.{erb,haml,slim}].freeze
- IGNORABLE_BRANCH_TYPES =
%i[implicit_else eval_generated].freeze
- IGNORABLE_METHOD_TYPES =
%i[eval_generated].freeze
- SUPPORTED_COVERAGE_CRITERIA =
%i[line branch method oneshot_line].freeze
- DEFAULT_COVERAGE_CRITERION =
:line- ONESHOT_LINE_COVERAGE_CRITERION =
:oneshot_line- LINE_COVERAGE_ALTERNATIVES =
: line_coverage_alternatives
{line: :oneshot_line, oneshot_line: :line}.freeze
Instance Attribute Summary collapse
- #filters ⇒ Array[Filter[untyped]]
- #formatter(formatter = :__no_arg__) ⇒ Class?
- #groups ⇒ Hash[String, Filter[untyped]]
- #print_error_status ⇒ Boolean
Instance Method Summary collapse
- #__send__ ⇒ Object
-
#active_session? ⇒ Boolean
The Coverage module is actively tracking, or a
@resulthas already been assembled (SimpleCov.collatenever starts Coverage). - #add_coverage_criterion(criterion) ⇒ void
- #add_filter(filter_argument = nil, &block) ⇒ void
- #add_group(group_name, filter_argument = nil, &block) ⇒ void
- #apply_threshold_options(configurator, options) ⇒ void
- #at_exit(&block) ⇒ void
- #at_fork(&block) ⇒ void
-
#baseline ⇒ Baseline?
Memoized per resolved path so the exit check and the JSON formatter's errors section read the file once, while a
baseline_fileorrootchange between reads is still picked up. -
#baseline_file(path = nil) ⇒ String
The baseline's path, relative to
SimpleCov.root; an absolute path is honored as given. - #baseline_file=(path) ⇒ String
- #branch_coverage? ⇒ Boolean
- #branch_coverage_supported? ⇒ Boolean
-
#build_cover_filter(arg) ⇒ Filter[untyped]
Strings are treated as globs, not substrings (that's
skip's semantics); everything else dispatches exactly likeadd_filter. - #clear_coverage_criteria ⇒ void
- #clear_filters ⇒ Array[Filter[untyped]]
- #collating_result? ⇒ boolish
-
#collect_cover_globs(filter_list) ⇒ Array[String]
Descends into
ArrayFilterwrappers built bycover(["a", "b"]). - #color(value = :__no_arg__) ⇒ bool, :auto
- #color=(value) ⇒ Object
-
#combined_formatter(formatters) ⇒ Object
An empty list is how a project opts out of formatting.
-
#command_name(name = nil) ⇒ String
The name of the command (a.k.a. Test Suite) currently running.
- #command_name=(name) ⇒ String
-
#configure {|config| ... } ⇒ Object
Configure simplecov in a block instead of prepending SimpleCov to each config method.
-
#cover(*args, &block) ⇒ void
Restrict the universe of files in the coverage report to those matching one or more globs, regexps, or block predicates.
- #cover_filters ⇒ Array[Filter[untyped]]
-
#cover_globs ⇒ Array[String]
The string globs passed to
cover, used by the disk-discovery pass inSimpleCov.tracked_file_pathsso files matching acoverglob appear in the report even when they were never required during the suite. -
#cover_views(*globs) ⇒ Array[String]
Reports coverage for ActionView templates, defaulting to a Rails app's views.
- #coverage(criterion, primary: false, enabled: true, oneshot: false, **thresholds, &block) ⇒ void
- #coverage_criteria ⇒ Set[criterion | :oneshot_line]
- #coverage_criterion_enabled?(criterion) ⇒ Boolean
-
#coverage_criterion_supported?(criterion) ⇒ Boolean
Older Rubies don't expose
Coverage.supported?, so fall back to the historical engine check that line/branch/method were unavailable on JRuby. - #coverage_dir(dir = nil) ⇒ String
-
#coverage_dir=(dir) ⇒ String
nil means the default 'coverage', recorded as a derivation rather than a choice.
- #coverage_for_eval_enabled? ⇒ Boolean
-
#coverage_for_eval_supported? ⇒ Boolean
The standalone eval-coverage toggle, kept apart from the criteria-set logic in
coverage_criteria.rbbecause:evalis a boolean toggle, never a member of the enabled-criteria set. -
#coverage_path(path = nil) ⇒ String
Defaults to
SimpleCov.root+SimpleCov.coverage_dir, but callers can override with an arbitrary absolute path, handy for out-of-tree build directories (#716). -
#coverage_path=(path) ⇒ Object
Assigning is the signal the caller intends to write there, so the directory is created.
-
#coverage_running? ⇒ Boolean
A configuration loaded on its own may have no Coverage to ask, which is not something a suite that measures coverage can be.
- #current_nocov_token(value = nil) ⇒ String
-
#default_groups ⇒ Hash[String, Filter[untyped]]
The group set
SimpleCov.groupedbins against when its caller names none. -
#default_primary_coverage ⇒ criterion, :oneshot_line
Answering
:lineeven when it is disabled would propagate broken state intominimum_coverage 90, so fall back to whichever criterion the user actually enabled, in insertion order. -
#deprecations(mode = nil) ⇒ Symbol
The configuration DSL migrates by warn-and-delegate, which means a project can run on deprecated spellings indefinitely without noticing.
-
#disable_coverage(criterion) ⇒ void
Disabling every criterion raises at
start_tracking, not here, so config files that toggle criteria in arbitrary order don't have to worry about transient empty states. -
#disable_eval_coverage ⇒ void
No support check needed: off is a safe state on every Ruby.
-
#drop_baseline(mode = nil) ⇒ Symbol
What
maximum_coverage_dropmeasures the drop against::last_run(the default) the previous run whatever it was,:medianthe median of the recorded history so one run that dipped for an unrelated reason cannot quietly become the baseline, and:branchthe newest recorded run on the current git branch so a feature branch is compared with itself. - #enable_coverage(*criteria) ⇒ void
- #enable_coverage_criterion(criterion, enabled:, oneshot:) ⇒ criterion, ...
- #enable_coverage_for_eval ⇒ void
- #enable_eval_coverage ⇒ void
- #enable_for_subprocesses(value = nil) ⇒ Boolean
- #enabled_for_subprocesses? ⇒ Boolean private
- #env_merge_timeout ⇒ Integer?
- #expected_coverage(coverage = nil) ⇒ coverage_thresholds
- #explicit_coverage_destination? ⇒ Boolean
- #explicit_custom_coverage_destination? ⇒ Boolean
- #final_result_process? ⇒ boolish
-
#finalize_merge(*value) ⇒ Boolean
Whether SimpleCov's selected final process owns merge processing: waiting for sibling workers, building the merged result, formatting, enforcing thresholds, and writing
.last_run.json. -
#finalize_merge=(value) ⇒ Boolean
Writing is what makes the answer explicit rather than inferred.
- #finalize_merge? ⇒ Boolean
- #formats(*names) ⇒ Array[Class], ...
- #formatters(formatters = :__no_arg__) ⇒ Array[Class], ...
-
#formatters=(formatters) ⇒ void
nil,false, and[]all opt out of formatting entirely. -
#group(group_name, filter_argument = nil) ⇒ void
Same matcher grammar as
skip, but instead of dropping the matching files it bins them undergroup_namefor the formatter. -
#history_limit(limit = nil) ⇒ Integer
How many runs coverage/.history.json keeps, newest kept.
- #history_limit=(limit) ⇒ Integer
-
#ignore_branches(*types) ⇒ Array[Symbol]
Deprecated in favour of
coverage(:branch) { ignore :implicit_else }, which fixes the criterion by context the way the threshold verbs do. - #ignore_methods(*types) ⇒ Array[Symbol]
- #ignored_branch?(type) ⇒ Boolean
- #ignored_branches ⇒ Array[Symbol]
- #ignored_method?(type) ⇒ Boolean
- #ignored_methods ⇒ Array[Symbol]
- #inferred_finalize_merge? ⇒ Boolean
- #inferred_finalize_merge_warning ⇒ String
-
#line_coverage? ⇒ Boolean
Whether this run produces line data at all.
-
#load_coverage ⇒ Object
Loading
simplecov/configurationon its own leaves Coverage undefined, and this question is asked at configuration time. -
#maximum_coverage(coverage = nil) ⇒ coverage_thresholds
The maximum overall coverage allowed for the testsuite to pass.
- #maximum_coverage_drop(coverage_drop = nil) ⇒ coverage_thresholds
-
#maximum_missed(counts = nil) ⇒ missed_caps
Caps the total number of misses per criterion.
-
#maximum_missed_per_file(counts = nil) ⇒ missed_caps
Unlike a percent minimum, which systematically flatters big files, this holds every file to the same absolute budget.
- #maximum_missed_per_file_overrides ⇒ Hash[String | Regexp, missed_caps]
- #merge_finalization_owner? ⇒ Boolean private
-
#merge_subprocesses(value = nil) ⇒ Boolean
Whether SimpleCov should hook
Process._forkto attach itself to subprocesses. -
#merge_subprocesses=(value) ⇒ Object
false stands in for nothing, so the answer is always a real opt-in or opt-out.
-
#merge_timeout(seconds = nil) ⇒ Integer
The maximum age (in seconds) of a resultset to still be included in merged results.
-
#merge_timeout=(seconds) ⇒ Object
Anything but an Integer is ignored, the way the dual method always did.
- #merging(use = nil) ⇒ Boolean
- #merging=(use) ⇒ Boolean
- #method_coverage? ⇒ Boolean
- #method_coverage_supported? ⇒ Boolean
- #minimum_coverage(coverage = nil) ⇒ coverage_thresholds
-
#minimum_coverage_by_file(coverage = nil) ⇒ Object
The minimum coverage per file required for the testsuite to pass.
- #minimum_coverage_by_file_overrides ⇒ Hash[String | Regexp, coverage_thresholds]
- #minimum_coverage_by_group(coverage = nil) ⇒ Object
- #minimum_possible_coverage_exceeded(coverage_option) ⇒ void
- #missed_per_file_replacement(counts) ⇒ String
-
#no_default_skips ⇒ Array[Filter[untyped]]
Order matters: call this before your own
skipinvocations. - #nocov_token(nocov_token = nil) ⇒ String (also: #skip_token)
- #normalized_missed_caps(counts, setting) ⇒ missed_caps
-
#normalized_threshold(coverage, setting) ⇒ coverage_thresholds
A bare Numeric targets the primary criterion, and the resulting per-criterion hash is validated before it is stored.
-
#parallel_tests(value = :__no_arg__) ⇒ Boolean?
Whether SimpleCov should auto-require the
parallel_testsgem when it seesTEST_ENV_NUMBER/PARALLEL_TEST_GROUPSin the environment. - #parallel_tests=(value) ⇒ Object
-
#parallel_wait_timeout(seconds = nil) ⇒ Integer
How long (in seconds) the reporting process waits for the remaining parallel-test workers to write their resultsets before it proceeds with a partial merge.
-
#parallel_wait_timeout=(seconds) ⇒ Object
Anything but an Integer is ignored, the way the dual method always did.
- #parallel_worker_environment? ⇒ Boolean
- #parse_filter(filter_argument = nil, &filter_proc) ⇒ void
-
#partition_per_file_thresholds(coverage) ⇒ [coverage_thresholds, Hash[String | Regexp, coverage_thresholds]]
Splits into Symbol-keyed criterion defaults and String/Regexp-keyed per-path overrides, normalizing Numeric override values to
{primary_coverage => N}so downstream code has one shape to handle. -
#per_file_coverage_replacement(defaults, overrides) ⇒ String
Renders the
coverageconfiguration equivalent to a deprecatedminimum_coverage_by_fileargument, so the deprecation warning can be copy-pasted verbatim into the user's config. - #per_group_coverage_replacement(coverage) ⇒ String
- #primary_coverage(criterion = nil) ⇒ criterion, :oneshot_line
- #primary_coverage=(criterion) ⇒ criterion, :oneshot_line
- #print_errors(value = :__no_arg__) ⇒ Boolean
- #print_errors=(value) ⇒ Boolean
-
#production_coverage(path = nil) ⇒ String?
The path to a production coverage store, the file a
SimpleCov::Productionsink wrote. - #production_coverage=(path) ⇒ String
- #profiles ⇒ Profiles
-
#project_name(new_name = nil) ⇒ String
Only a String renames, and a name already chosen survives anything else.
- #raise_if_branch_type_unsupported(type) ⇒ void
- #raise_if_criterion_disabled(criterion) ⇒ void
- #raise_if_criterion_unsupported(criterion) ⇒ void
- #raise_if_method_type_unsupported(type) ⇒ void
- #raise_on_invalid_coverage(coverage, coverage_setting) ⇒ void
- #raise_on_invalid_missed_cap(cap, setting) ⇒ void
- #refuse_coverage_drop(*criteria) ⇒ coverage_thresholds
-
#remove_filter(filter_argument) ⇒ Boolean
reject!answers nil when it rejected nothing, which is the whole of "was anything removed". - #render_coverage_blocks(by_criterion) ⇒ String
-
#require_html_formatter(name) ⇒ void
formats :htmlhas to work in a process that never required the HTML formatter, which under SIMPLECOV_NO_DEFAULTS nothing else has. - #resolve_criterion_variant(criterion, oneshot) ⇒ criterion, ...
- #resolve_format(name) ⇒ Object
- #root(root = nil) ⇒ String
-
#root=(root) ⇒ String
nil means the working directory, the default the reader would have derived.
-
#skip(filter_argument = nil) ⇒ void
Drop matching files from the coverage report.
- #source_in_json(value = :__no_arg__) ⇒ Boolean
- #source_in_json=(value) ⇒ Boolean
-
#store_ignored_branches(types) ⇒ Array[Symbol]
Variadic semantics: multiple calls union, duplicates are no-ops, unknown tokens raise.
- #store_ignored_methods(types) ⇒ Array[Symbol]
- #store_maximum_missed_per_file(criterion, count, target) ⇒ void
- #store_minimum_per_file(criterion, percent, target) ⇒ void
- #store_minimum_per_group(criterion, percent, group_name) ⇒ void
- #store_missed_cap(setting, criterion, count) ⇒ void
- #store_overall_threshold(setting, criterion, percent) ⇒ void private
- #track_files(glob) ⇒ String?
-
#track_files_replacement_hint(glob) ⇒ String
track_files(nil)is the documented way to clear a previously-set glob, butcover(nil)raisesConfigurationError, so don't point users at it. -
#track_tests(enabled = nil, granularity: nil) ⇒ Boolean
Enables recording of which test covered which line.
- #track_tests? ⇒ Boolean
- #track_tests_granularity ⇒ Symbol
-
#tracked_files ⇒ String?
Nil until
covernames a glob: an unset ivar reads as nil, so the absence needs no guard of its own. - #use_merging(use = nil) ⇒ Boolean
- #validate_coverage_criteria! ⇒ void
- #validate_per_file_key(key) ⇒ void
-
#validate_test_tracking! ⇒ void
:oneshot_linedoes not produce: a line reports only its first hit ever, so every test after the first would show no delta. -
#view_coverage? ⇒ Boolean
False when eval coverage couldn't be enabled, where
cover_viewshas already warned and the templates would come back empty rather than at 0%. -
#view_globs ⇒ Array[String]?
Nil rather than an empty Array when
cover_viewswas never called, so "not asked for" stays distinguishable from "asked for, with nothing to match". - #warn_about_inferred_finalize_merge ⇒ void
Instance Attribute Details
#filters ⇒ Array[Filter[untyped]]
62 63 64 |
# File 'lib/simplecov/configuration/filters.rb', line 62 def filters @filters ||= [] end |
#formatter(formatter = :__no_arg__) ⇒ Class?
24 25 26 27 28 29 30 31 |
# File 'lib/simplecov/configuration/formatting.rb', line 24 def formatter(formatter = :__no_arg__) case formatter when :__no_arg__ @formatter else @formatter = formatter || nil end end |
#groups ⇒ Hash[String, Filter[untyped]]
5 6 7 |
# File 'lib/simplecov/configuration/groups.rb', line 5 def groups @groups ||= {} end |
#print_error_status ⇒ Boolean
80 81 82 83 84 |
# File 'lib/simplecov/configuration/formatting.rb', line 80 def print_error_status Deprecation.warn("`SimpleCov.print_error_status` is deprecated. " \ "Replace with `SimpleCov.print_errors` (same value).") instance_variable_defined?(:@print_error_status) ? @print_error_status : true end |
Instance Method Details
#__send__ ⇒ Object
138 |
# File 'sig/simplecov.rbs', line 138
def __send__: (Symbol name, *untyped args) -> untyped
|
#active_session? ⇒ Boolean
The Coverage module is actively tracking, or a @result has already been
assembled (SimpleCov.collate never starts Coverage).
107 108 109 |
# File 'lib/simplecov/configuration.rb', line 107 def active_session? !!SimpleCov.result? || coverage_running? end |
#add_coverage_criterion(criterion) ⇒ void
This method returns an undefined value.
105 106 107 108 109 110 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 105 def add_coverage_criterion(criterion) raise_if_criterion_unsupported(criterion) incompatible = LINE_COVERAGE_ALTERNATIVES[criterion] disable_coverage(incompatible) if incompatible coverage_criteria << criterion end |
#add_filter(filter_argument = nil, &block) ⇒ void
This method returns an undefined value.
75 76 77 78 79 80 |
# File 'lib/simplecov/configuration/filters.rb', line 75 def add_filter(filter_argument = nil, &block) example = block ? "`SimpleCov.skip { ... }`" : "`SimpleCov.skip #{filter_argument.inspect}`" Deprecation.warn("`SimpleCov.add_filter` is deprecated. " \ "Replace with `SimpleCov.skip` (same arguments, same behavior). Example: #{example}.") skip(filter_argument, &block) end |
#add_group(group_name, filter_argument = nil, &block) ⇒ void
This method returns an undefined value.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/simplecov/configuration/groups.rb', line 35 def add_group(group_name, filter_argument = nil, &block) example = if block "`SimpleCov.group #{group_name.inspect} { ... }`" else "`SimpleCov.group #{group_name.inspect}, #{filter_argument.inspect}`" end Deprecation.warn( "`SimpleCov.add_group` is deprecated. " \ "Replace with `SimpleCov.group` (same arguments, same behavior). Example: #{example}." ) group(group_name, filter_argument, &block) end |
#apply_threshold_options(configurator, options) ⇒ void
This method returns an undefined value.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simplecov/configuration/coverage.rb', line 22 def (configurator, ) .each do |verb, value| unless COVERAGE_THRESHOLD_OPTIONS.include?(verb) raise ConfigurationError, "Unknown `coverage` option #{verb.inspect}. " \ "Supported options are #{COVERAGE_THRESHOLD_OPTIONS.inspect}." end configurator.public_send(verb, value) end end |
#at_exit(&block) ⇒ void
This method returns an undefined value.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/simplecov/configuration.rb', line 93 def at_exit(&block) @at_exit = block if block configured = @at_exit return configured if configured return -> {} unless active_session? @at_exit = lambda do result = SimpleCov.result result.format! if result && SimpleCov.merge_finalization_owner? end end |
#at_fork(&block) ⇒ void
This method returns an undefined value.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/simplecov/configuration.rb', line 117 def at_fork(&block) @at_fork = block if block @at_fork ||= lambda { |_pid| # Needs a name that's unique per worker within a run yet identical across # runs. Built from SimpleCov's stable fork serial rather than the OS pid: # with the pid, every run produced uniquely-named results that never # overwrote the previous run's, so they piled up in .resultset.json # until merge_timeout and the merged report's file set drifted from run # to run (#1171). SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{SimpleCov.subprocess_serial})" SimpleCov.print_errors false SimpleCov.formatter Formatter::SimpleFormatter SimpleCov.minimum_coverage 0 SimpleCov.start } end |
#baseline ⇒ Baseline?
Memoized per resolved path so the exit check and the JSON formatter's
errors section read the file once, while a baseline_file or root change
between reads is still picked up.
23 24 25 26 27 28 29 |
# File 'lib/simplecov/configuration/baseline.rb', line 23 def baseline resolved = File.(baseline_file, root) return @baseline if @baseline_path.eql?(resolved) @baseline_path = resolved @baseline = Baseline.read_if_exists(resolved) end |
#baseline_file(path = nil) ⇒ String
The baseline's path, relative to SimpleCov.root; an absolute path is
honored as given. The file's presence is the opt-in: generate it with
simplecov ratchet, check it in, and the exit check holds every listed
file to its own floor (#1268).
9 10 11 12 13 14 |
# File 'lib/simplecov/configuration/baseline.rb', line 9 def baseline_file(path = nil) return @baseline_file ||= Baseline::DEFAULT_FILENAME unless path self.baseline_file = path _ = @baseline_file end |
#baseline_file=(path) ⇒ String
16 17 18 |
# File 'lib/simplecov/configuration/baseline.rb', line 16 def baseline_file=(path) @baseline_file = path end |
#branch_coverage? ⇒ Boolean
71 72 73 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 71 def branch_coverage? branch_coverage_supported? && coverage_criterion_enabled?(:branch) end |
#branch_coverage_supported? ⇒ Boolean
75 76 77 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 75 def branch_coverage_supported? coverage_criterion_supported?(:branches) end |
#build_cover_filter(arg) ⇒ Filter[untyped]
Strings are treated as globs, not substrings (that's skip's
semantics); everything else dispatches exactly like add_filter.
112 113 114 115 116 117 118 |
# File 'lib/simplecov/configuration/filters.rb', line 112 def build_cover_filter(arg) Filter.build_filter(arg, string_filter: GlobFilter) rescue ConfigurationError raise ConfigurationError, "Unsupported `cover` argument #{arg.inspect}; " \ "expected a String glob, Regexp, Proc, " \ "SimpleCov::Filter, or Array of those." end |
#clear_coverage_criteria ⇒ void
This method returns an undefined value.
49 50 51 52 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 49 def clear_coverage_criteria @coverage_criteria = nil @primary_coverage = nil end |
#clear_filters ⇒ Array[Filter[untyped]]
91 92 93 |
# File 'lib/simplecov/configuration/filters.rb', line 91 def clear_filters @filters = [] end |
#collating_result? ⇒ boolish
563 |
# File 'sig/simplecov.rbs', line 563
def collating_result?: () -> boolish
|
#collect_cover_globs(filter_list) ⇒ Array[String]
Descends into ArrayFilter wrappers built by cover(["a", "b"]).
121 122 123 124 125 126 127 128 129 |
# File 'lib/simplecov/configuration/filters.rb', line 121 def collect_cover_globs(filter_list) filter_list.flat_map do |filter| case filter when GlobFilter then filter.filter_argument when ArrayFilter then collect_cover_globs(filter.filter_argument) else [] end end end |
#color(value = :__no_arg__) ⇒ bool, :auto
50 51 52 53 54 |
# File 'lib/simplecov/configuration/formatting.rb', line 50 def color(value = :__no_arg__) return instance_variable_defined?(:@color) ? @color : :auto if value.eql?(:__no_arg__) self.color = _ = value end |
#color=(value) ⇒ Object
56 57 58 |
# File 'lib/simplecov/configuration/formatting.rb', line 56 def color=(value) @color = value end |
#combined_formatter(formatters) ⇒ Object
An empty list is how a project opts out of formatting.
102 103 104 105 106 |
# File 'lib/simplecov/configuration/formatting.rb', line 102 def combined_formatter(formatters) return if formatters.empty? Formatter::MultiFormatter.new(formatters) end |
#command_name(name = nil) ⇒ String
The name of the command (a.k.a. Test Suite) currently running. Used for result merging and caching. Auto-detected.
64 65 66 67 |
# File 'lib/simplecov/configuration.rb', line 64 def command_name(name = nil) self.command_name = name unless name.nil? @command_name ||= CommandGuesser.guess end |
#command_name=(name) ⇒ String
69 70 71 |
# File 'lib/simplecov/configuration.rb', line 69 def command_name=(name) @command_name = name end |
#configure ⇒ self #configure ⇒ self
Configure simplecov in a block instead of prepending SimpleCov to each config method. Parameterized blocks retain their caller context and receive this configuration target explicitly.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/simplecov/configuration.rb', line 82 def configure(&block) raise ArgumentError, "configuration block required" unless block if block.parameters.empty? instance_exec(&(_ = block)) else yield self end self end |
#cover(*args, &block) ⇒ void
This method returns an undefined value.
Restrict the universe of files in the coverage report to those matching
one or more globs, regexps, or block predicates. Multiple calls union;
when any cover matcher is configured the report drops every file that
doesn't match at least one of them.
Strings are interpreted as shell globs, not substring matches, a
deliberate departure from the legacy add_filter semantics.
A string glob is also expanded on disk, so files that exist but were
never required during the run still appear in the report at 0%. This is
the "include unloaded files" half of the legacy track_files behavior.
20 21 22 23 24 |
# File 'lib/simplecov/configuration/filters.rb', line 20 def cover(*args, &block) args.each { |arg| cover_filters << build_cover_filter(arg) } cover_filters << BlockFilter.new(block) if block cover_filters end |
#cover_filters ⇒ Array[Filter[untyped]]
26 27 28 |
# File 'lib/simplecov/configuration/filters.rb', line 26 def cover_filters @cover_filters ||= [] end |
#cover_globs ⇒ Array[String]
The string globs passed to cover, used by the disk-discovery pass in
SimpleCov.tracked_file_paths so files matching a cover glob appear in
the report even when they were never required during the suite.
33 34 35 |
# File 'lib/simplecov/configuration/filters.rb', line 33 def cover_globs collect_cover_globs(cover_filters) end |
#cover_views(*globs) ⇒ Array[String]
Reports coverage for ActionView templates, defaulting to a Rails app's
views. Globs are expanded against SimpleCov.root, and one naming an
extension no handler is registered for (as the default does whenever a
project has no Haml or Slim) leaves those files out rather than reporting
them as empty.
Templates the suite renders are measured through eval coverage, which this enables. Templates it never renders are compiled at the end of the run so they appear at 0% instead of going missing.
16 17 18 19 20 21 22 |
# File 'lib/simplecov/configuration/view_coverage.rb', line 16 def cover_views(*globs) globs = globs.flatten.compact globs = DEFAULT_VIEW_GLOBS.dup if globs.empty? @view_globs = globs enable_eval_coverage globs end |
#coverage(criterion, primary: false, enabled: true, oneshot: false, **thresholds, &block) ⇒ void
This method returns an undefined value.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/simplecov/configuration/coverage.rb', line 8 def coverage(criterion, primary: false, enabled: true, oneshot: false, **thresholds, &block) criterion = enable_coverage_criterion(criterion, enabled: enabled, oneshot: oneshot) # The cast admits :eval, which primary_coverage rejects at runtime. primary_coverage(_ = criterion) if primary configurator = CoverageCriterion.new(self, criterion) (configurator, thresholds) configurator.instance_eval(&block) if block criterion end |
#coverage_criteria ⇒ Set[criterion | :oneshot_line]
41 42 43 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 41 def coverage_criteria @coverage_criteria ||= Set[DEFAULT_COVERAGE_CRITERION] end |
#coverage_criterion_enabled?(criterion) ⇒ Boolean
45 46 47 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 45 def coverage_criterion_enabled?(criterion) coverage_criteria.member?(criterion) end |
#coverage_criterion_supported?(criterion) ⇒ Boolean
Older Rubies don't expose Coverage.supported?, so fall back to the
historical engine check that line/branch/method were unavailable on JRuby.
:eval was added later, so its fallback is "always unsupported".
90 91 92 93 94 95 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 90 def coverage_criterion_supported?(criterion) load_coverage return Coverage.supported?(criterion) if Coverage.respond_to?(:supported?) !criterion.eql?(:eval) && !RUBY_ENGINE.eql?("jruby") end |
#coverage_dir(dir = nil) ⇒ String
20 21 22 23 24 25 |
# File 'lib/simplecov/configuration.rb', line 20 def coverage_dir(dir = nil) return @coverage_dir if instance_variable_defined?(:@coverage_dir) && dir.nil? self.coverage_dir = dir @coverage_dir end |
#coverage_dir=(dir) ⇒ String
nil means the default 'coverage', recorded as a derivation rather than a choice.
29 30 31 32 33 |
# File 'lib/simplecov/configuration.rb', line 29 def coverage_dir=(dir) @coverage_path = nil unless @coverage_path_explicit # invalidate cache @coverage_dir_explicit = true unless dir.nil? @coverage_dir = dir || "coverage" end |
#coverage_for_eval_enabled? ⇒ Boolean
12 13 14 |
# File 'lib/simplecov/configuration/eval_coverage.rb', line 12 def coverage_for_eval_enabled? @coverage_for_eval_enabled ||= false end |
#coverage_for_eval_supported? ⇒ Boolean
The standalone eval-coverage toggle, kept apart from the criteria-set logic
in coverage_criteria.rb because :eval is a boolean toggle, never a
member of the enabled-criteria set.
8 9 10 |
# File 'lib/simplecov/configuration/eval_coverage.rb', line 8 def coverage_for_eval_supported? coverage_criterion_supported?(:eval) end |
#coverage_path(path = nil) ⇒ String
Defaults to SimpleCov.root + SimpleCov.coverage_dir, but callers can
override with an arbitrary absolute path, handy for out-of-tree build
directories (#716).
Reading is pure: the directory is only created when a path is explicitly
assigned. The codepaths that write into it ensure existence themselves,
so read-only CLI subcommands that interpolate the path into status text
don't materialize a stray coverage/ directory.
45 46 47 48 49 |
# File 'lib/simplecov/configuration.rb', line 45 def coverage_path(path = nil) self.coverage_path = path if path @coverage_path ||= File.(coverage_dir, root) end |
#coverage_path=(path) ⇒ Object
Assigning is the signal the caller intends to write there, so the directory is created.
53 54 55 56 57 58 |
# File 'lib/simplecov/configuration.rb', line 53 def coverage_path=(path) = File.(path) @coverage_path = @coverage_path_explicit = true FileUtils.mkdir_p end |
#coverage_running? ⇒ Boolean
A configuration loaded on its own may have no Coverage to ask, which is not something a suite that measures coverage can be.
113 114 115 |
# File 'lib/simplecov/configuration.rb', line 113 def coverage_running? defined?(Coverage) ? Coverage.running? : false end |
#current_nocov_token(value = nil) ⇒ String
93 94 95 96 97 |
# File 'lib/simplecov/configuration/formatting.rb', line 93 def current_nocov_token(value = nil) return @nocov_token if instance_variable_defined?(:@nocov_token) && value.nil? @nocov_token = value || "nocov" end |
#default_groups ⇒ Hash[String, Filter[untyped]]
The group set SimpleCov.grouped bins against when its caller names none.
It reads through a method of its own because the keyword it defaults
shadows groups, so the default has to name a receiver, and every
spelling of that receiver is the same call.
mutant:disable — for that reason: SimpleCov.groups, self.groups and
groups() cannot be told apart.
16 17 18 |
# File 'lib/simplecov/configuration/groups.rb', line 16 def default_groups groups end |
#default_primary_coverage ⇒ criterion, :oneshot_line
Answering :line even when it is disabled would propagate broken state
into minimum_coverage 90, so fall back to whichever criterion the user
actually enabled, in insertion order.
115 116 117 118 119 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 115 def default_primary_coverage return DEFAULT_COVERAGE_CRITERION if coverage_criterion_enabled?(DEFAULT_COVERAGE_CRITERION) _ = coverage_criteria.first end |
#deprecations(mode = nil) ⇒ Symbol
The configuration DSL migrates by warn-and-delegate, which means a project
can run on deprecated spellings indefinitely without noticing.
deprecations :raise turns every deprecated API into a ConfigurationError,
so a project that has migrated can guard in CI against old spellings
creeping back. There is deliberately no silencing mode: a deprecation you
cannot see is a migration you never make.
15 16 17 18 19 |
# File 'lib/simplecov/configuration/deprecations.rb', line 15 def deprecations(mode = nil) return Deprecation.mode unless mode Deprecation.mode = mode end |
#disable_coverage(criterion) ⇒ void
This method returns an undefined value.
Disabling every criterion raises at start_tracking, not here, so config
files that toggle criteria in arbitrary order don't have to worry about
transient empty states.
20 21 22 23 24 25 26 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 20 def disable_coverage(criterion) return disable_eval_coverage if criterion.equal?(:eval) raise_if_criterion_unsupported(_ = criterion) coverage_criteria.delete(_ = criterion) @primary_coverage = nil if @primary_coverage.equal?(criterion) end |
#disable_eval_coverage ⇒ void
This method returns an undefined value.
No support check needed: off is a safe state on every Ruby.
33 34 35 |
# File 'lib/simplecov/configuration/eval_coverage.rb', line 33 def disable_eval_coverage @coverage_for_eval_enabled = false end |
#drop_baseline(mode = nil) ⇒ Symbol
What maximum_coverage_drop measures the drop against: :last_run (the
default) the previous run whatever it was, :median the median of the
recorded history so one run that dipped for an unrelated reason cannot
quietly become the baseline, and :branch the newest recorded run on the
current git branch so a feature branch is compared with itself.
The latter two read coverage/.history.json and find nothing to compare against while it is empty, which counts as "no previous run" the way a missing .last_run.json does.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/simplecov/configuration/history.rb', line 33 def drop_baseline(mode = nil) return @drop_baseline ||= :last_run if mode.nil? unless DROP_BASELINES.include?(mode) raise ConfigurationError, "drop_baseline takes one of #{DROP_BASELINES}, got #{mode.inspect}" end @drop_baseline = mode end |
#enable_coverage(*criteria) ⇒ void
This method returns an undefined value.
11 12 13 14 15 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 11 def enable_coverage(*criteria) criteria.each do |criterion| criterion.equal?(:eval) ? enable_eval_coverage : add_coverage_criterion(_ = criterion) end end |
#enable_coverage_criterion(criterion, enabled:, oneshot:) ⇒ criterion, ...
34 35 36 37 38 |
# File 'lib/simplecov/configuration/coverage.rb', line 34 def enable_coverage_criterion(criterion, enabled:, oneshot:) criterion = resolve_criterion_variant(criterion, oneshot) enabled ? enable_coverage(criterion) : disable_coverage(criterion) criterion end |
#enable_coverage_for_eval ⇒ void
This method returns an undefined value.
16 17 18 19 20 |
# File 'lib/simplecov/configuration/eval_coverage.rb', line 16 def enable_coverage_for_eval Deprecation.warn("`SimpleCov.enable_coverage_for_eval` is deprecated. " \ "Replace with `SimpleCov.enable_coverage :eval`.") enable_eval_coverage end |
#enable_eval_coverage ⇒ void
This method returns an undefined value.
24 25 26 27 28 29 30 |
# File 'lib/simplecov/configuration/eval_coverage.rb', line 24 def enable_eval_coverage if coverage_for_eval_supported? @coverage_for_eval_enabled = true else warn "Coverage for eval is not available on this Ruby" end end |
#enable_for_subprocesses(value = nil) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/simplecov/configuration/merging.rb', line 43 def enable_for_subprocesses(value = nil) Deprecation.warn("`SimpleCov.enable_for_subprocesses` is deprecated. " \ "Replace with `SimpleCov.merge_subprocesses` (same value, same behavior).") merge_subprocesses(value) end |
#enabled_for_subprocesses? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/simplecov/configuration/merging.rb', line 24 def enabled_for_subprocesses? !!@enable_for_subprocesses end |
#env_merge_timeout ⇒ Integer?
131 132 133 134 |
# File 'lib/simplecov/configuration/merging.rb', line 131 def env_merge_timeout value = ENV.fetch("SIMPLECOV_MERGE_TIMEOUT", nil) Integer(value, 10) if value&.match?(/\A\d+\z/) end |
#expected_coverage(coverage = nil) ⇒ coverage_thresholds
30 31 32 33 34 35 |
# File 'lib/simplecov/configuration/thresholds.rb', line 30 def expected_coverage(coverage = nil) return minimum_coverage if coverage.nil? minimum_coverage(coverage) maximum_coverage(coverage) end |
#explicit_coverage_destination? ⇒ Boolean
177 178 179 |
# File 'lib/simplecov/configuration/merging.rb', line 177 def explicit_coverage_destination? @coverage_path_explicit || @coverage_dir_explicit end |
#explicit_custom_coverage_destination? ⇒ Boolean
171 172 173 174 175 |
# File 'lib/simplecov/configuration/merging.rb', line 171 def explicit_custom_coverage_destination? return false unless explicit_coverage_destination? !coverage_path.eql?(File.("coverage", root)) end |
#final_result_process? ⇒ boolish
565 |
# File 'sig/simplecov.rbs', line 565
def final_result_process?: () -> boolish
|
#finalize_merge(*value) ⇒ Boolean
Whether SimpleCov's selected final process owns merge processing: waiting
for sibling workers, building the merged result, formatting, enforcing
thresholds, and writing .last_run.json.
Defaults to true, except for recognized multi-worker parallel runs that
explicitly write to a custom coverage destination while merging is
enabled. Those runs are likely using an external SimpleCov.collate step
to finalize the merge.
Splatted rather than defaulted: false is a value someone sets on purpose, so "given nothing" cannot be told from it by looking at the argument.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/simplecov/configuration/merging.rb', line 72 def finalize_merge(*value) unless value.empty? explicit, = value self.finalize_merge = _ = explicit end return @finalize_merge if @finalize_merge_explicit inferred = inferred_finalize_merge? warn_about_inferred_finalize_merge unless inferred inferred end |
#finalize_merge=(value) ⇒ Boolean
Writing is what makes the answer explicit rather than inferred.
86 87 88 89 |
# File 'lib/simplecov/configuration/merging.rb', line 86 def finalize_merge=(value) @finalize_merge = value @finalize_merge_explicit = true end |
#finalize_merge? ⇒ Boolean
91 92 93 |
# File 'lib/simplecov/configuration/merging.rb', line 91 def finalize_merge? finalize_merge end |
#formats(*names) ⇒ Array[Class], ...
17 18 19 20 21 22 |
# File 'lib/simplecov/configuration/formatting.rb', line 17 def formats(*names) return formatters if names.empty? self.formatters = names.map { |name| resolve_format(name) } formatters end |
#formatters(formatters = :__no_arg__) ⇒ Array[Class], ...
33 34 35 36 37 38 39 40 41 |
# File 'lib/simplecov/configuration/formatting.rb', line 33 def formatters(formatters = :__no_arg__) case formatters when :__no_arg__ configured = formatter configured ? [configured] : [] else self.formatters = formatters end end |
#formatters=(formatters) ⇒ void
This method returns an undefined value.
nil, false, and [] all opt out of formatting entirely. false is
normalized first, since Array(false) would otherwise smuggle it in as a
"formatter" that can only fail.
46 47 48 |
# File 'lib/simplecov/configuration/formatting.rb', line 46 def formatters=(formatters) @formatter = combined_formatter(Array(formatters || nil)) end |
#group(group_name, filter_argument = nil) ⇒ void
This method returns an undefined value.
Same matcher grammar as skip, but instead of dropping the matching files
it bins them under group_name for the formatter. Files matched by no
group fall into the implicit "Ungrouped" bucket.
29 30 31 32 33 |
# File 'lib/simplecov/configuration/groups.rb', line 29 def group(group_name, filter_argument = nil, &) group_name = GroupNames.normalize(group_name) GroupNames.validate!([group_name]) groups[group_name] = parse_filter(filter_argument, &) end |
#history_limit(limit = nil) ⇒ Integer
How many runs coverage/.history.json keeps, newest kept. 0 disables recording entirely, and anything but a count of runs is refused.
9 10 11 12 13 14 |
# File 'lib/simplecov/configuration/history.rb', line 9 def history_limit(limit = nil) return @history_limit ||= 100 if limit.nil? self.history_limit = limit _ = @history_limit end |
#history_limit=(limit) ⇒ Integer
16 17 18 19 20 21 22 |
# File 'lib/simplecov/configuration/history.rb', line 16 def history_limit=(limit) unless limit.instance_of?(Integer) && limit >= 0 raise ConfigurationError, "history_limit takes a non-negative integer, got #{limit.inspect}" end @history_limit = limit end |
#ignore_branches(*types) ⇒ Array[Symbol]
Deprecated in favour of coverage(:branch) { ignore :implicit_else },
which fixes the criterion by context the way the threshold verbs do. One
difference rides out the deprecation period: the coverage block enables the
criterion it names, while this legacy setter records without enabling.
12 13 14 15 16 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 12 def ignore_branches(*types) Deprecation.warn("`SimpleCov.ignore_branches` is deprecated. " \ "Replace with `coverage(:branch) { ignore #{types.map(&:inspect).join(", ")} }`.") store_ignored_branches(types) end |
#ignore_methods(*types) ⇒ Array[Symbol]
26 27 28 29 30 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 26 def ignore_methods(*types) Deprecation.warn("`SimpleCov.ignore_methods` is deprecated. " \ "Replace with `coverage(:method) { ignore #{types.map(&:inspect).join(", ")} }`.") store_ignored_methods(types) end |
#ignored_branch?(type) ⇒ Boolean
22 23 24 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 22 def ignored_branch?(type) ignored_branches.include?(type) end |
#ignored_branches ⇒ Array[Symbol]
18 19 20 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 18 def ignored_branches @ignored_branches ||= [] end |
#ignored_method?(type) ⇒ Boolean
36 37 38 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 36 def ignored_method?(type) ignored_methods.include?(type) end |
#ignored_methods ⇒ Array[Symbol]
32 33 34 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 32 def ignored_methods @ignored_methods ||= [] end |
#inferred_finalize_merge? ⇒ Boolean
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/simplecov/configuration/merging.rb', line 155 def inferred_finalize_merge? return true unless merging adapter = ParallelAdapters.current return true unless adapter return true unless adapter.expected_worker_count > 1 return true unless parallel_worker_environment? return true unless explicit_custom_coverage_destination? false end |
#inferred_finalize_merge_warning ⇒ String
189 190 191 192 193 194 195 |
# File 'lib/simplecov/configuration/merging.rb', line 189 def inferred_finalize_merge_warning "SimpleCov inferred `finalize_merge false` because this parallel worker is merging " \ "into a custom coverage destination. Set `SimpleCov.finalize_merge false` to keep " \ "external collation ownership, or `SimpleCov.finalize_merge true` if this worker " \ "should wait, merge, format, enforce thresholds, and write `.last_run.json`. " \ "See https://github.com/simplecov-ruby/simplecov#merge-finalization-ownership." end |
#line_coverage? ⇒ Boolean
Whether this run produces line data at all. The oneshot variant counts:
ResultAdapter turns its executed-line list back into a line array. A
branch-only or method-only run produces none, and Coverage.result
entries for the files it loaded carry no "lines" key.
66 67 68 69 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 66 def line_coverage? coverage_criterion_enabled?(DEFAULT_COVERAGE_CRITERION) || coverage_criterion_enabled?(ONESHOT_LINE_COVERAGE_CRITERION) end |
#load_coverage ⇒ Object
Loading simplecov/configuration on its own leaves Coverage undefined, and
this question is asked at configuration time.
99 100 101 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 99 def load_coverage require "coverage" end |
#maximum_coverage(coverage = nil) ⇒ coverage_thresholds
The maximum overall coverage allowed for the testsuite to pass. Useful
paired with minimum_coverage (or via expected_coverage) to pin
coverage to an exact value, so an unexpected jump up fails the build
(#187).
24 25 26 27 28 |
# File 'lib/simplecov/configuration/thresholds.rb', line 24 def maximum_coverage(coverage = nil) return @maximum_coverage ||= {} unless coverage @maximum_coverage = normalized_threshold(coverage, "maximum_coverage") end |
#maximum_coverage_drop(coverage_drop = nil) ⇒ coverage_thresholds
37 38 39 40 41 |
# File 'lib/simplecov/configuration/thresholds.rb', line 37 def maximum_coverage_drop(coverage_drop = nil) return @maximum_coverage_drop ||= {} unless coverage_drop @maximum_coverage_drop = normalized_threshold(coverage_drop, "maximum_coverage_drop") end |
#maximum_missed(counts = nil) ⇒ missed_caps
Caps the total number of misses per criterion. Where a percent minimum asks for a ratio, this asks for an absolute burn-down number, which stays meaningful as the codebase grows and shrinks.
8 9 10 11 12 |
# File 'lib/simplecov/configuration/missed_caps.rb', line 8 def maximum_missed(counts = nil) return @maximum_missed ||= {} unless counts @maximum_missed = normalized_missed_caps(counts, "maximum_missed") end |
#maximum_missed_per_file(counts = nil) ⇒ missed_caps
Unlike a percent minimum, which systematically flatters big files, this holds every file to the same absolute budget. Files with a baseline entry are exempt per covered criterion, as they are from the per-file minimum.
17 18 19 20 21 22 23 |
# File 'lib/simplecov/configuration/missed_caps.rb', line 17 def maximum_missed_per_file(counts = nil) return @maximum_missed_per_file ||= {} unless counts Deprecation.warn("`SimpleCov.maximum_missed_per_file` is deprecated. " \ "Replace it with:\n#{missed_per_file_replacement(counts)}") @maximum_missed_per_file = normalized_missed_caps(counts, "maximum_missed_per_file") end |
#maximum_missed_per_file_overrides ⇒ Hash[String | Regexp, missed_caps]
25 26 27 |
# File 'lib/simplecov/configuration/missed_caps.rb', line 25 def maximum_missed_per_file_overrides @maximum_missed_per_file_overrides ||= {} end |
#merge_finalization_owner? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 |
# File 'lib/simplecov/configuration/merging.rb', line 96 def merge_finalization_owner? collating_result? || (finalize_merge? && final_result_process?) end |
#merge_subprocesses(value = nil) ⇒ Boolean
Whether SimpleCov should hook Process._fork to attach itself to
subprocesses. Required when the suite uses parallel test workers (Rails'
parallelize(workers:)). Defaults to false.
10 11 12 13 14 15 |
# File 'lib/simplecov/configuration/merging.rb', line 10 def merge_subprocesses(value = nil) return @enable_for_subprocesses if instance_variable_defined?(:@enable_for_subprocesses) && value.nil? self.merge_subprocesses = value @enable_for_subprocesses end |
#merge_subprocesses=(value) ⇒ Object
false stands in for nothing, so the answer is always a real opt-in or opt-out.
19 20 21 |
# File 'lib/simplecov/configuration/merging.rb', line 19 def merge_subprocesses=(value) @enable_for_subprocesses = value || false end |
#merge_timeout(seconds = nil) ⇒ Integer
The maximum age (in seconds) of a resultset to still be included in merged results. Default is 600 seconds.
A numeric SIMPLECOV_MERGE_TIMEOUT in the environment takes precedence
over the configured value: simplecov watch re-runs test subsets across
a long session and extends its child runs' merge window this way, where
editing every watched project's configuration is not an option.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/simplecov/configuration/merging.rb', line 115 def merge_timeout(seconds = nil) self.merge_timeout = seconds # Memoized through a local rather than `|| (@merge_timeout ||= 600)`: # steep 2.0's logic-type interpreter crashes on an or-assignment nested in # a logical operand, and ivar narrowing doesn't carry across statements # the way a local's does. configured = @merge_timeout || 600 @merge_timeout = configured env_merge_timeout || configured end |
#merge_timeout=(seconds) ⇒ Object
Anything but an Integer is ignored, the way the dual method always did.
127 128 129 |
# File 'lib/simplecov/configuration/merging.rb', line 127 def merge_timeout=(seconds) @merge_timeout = seconds if seconds.instance_of?(Integer) end |
#merging(use = nil) ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/simplecov/configuration/merging.rb', line 49 def merging(use = nil) self.merging = use unless use.nil? # Unset reads as nil, and only an explicit `merging false` turns it off. @use_merging = true if @use_merging.nil? @use_merging end |
#merging=(use) ⇒ Boolean
56 57 58 |
# File 'lib/simplecov/configuration/merging.rb', line 56 def merging=(use) @use_merging = use end |
#method_coverage? ⇒ Boolean
79 80 81 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 79 def method_coverage? method_coverage_supported? && coverage_criterion_enabled?(:method) end |
#method_coverage_supported? ⇒ Boolean
83 84 85 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 83 def method_coverage_supported? coverage_criterion_supported?(:methods) end |
#minimum_coverage(coverage = nil) ⇒ coverage_thresholds
5 6 7 8 9 |
# File 'lib/simplecov/configuration/thresholds.rb', line 5 def minimum_coverage(coverage = nil) return @minimum_coverage ||= {} unless coverage @minimum_coverage = normalized_threshold(coverage, "minimum_coverage") end |
#minimum_coverage_by_file ⇒ coverage_thresholds #minimum_coverage_by_file(coverage) ⇒ Hash[String | Regexp, coverage_thresholds]
The minimum coverage per file required for the testsuite to pass. Accepts a Numeric (global threshold on the primary criterion), a Symbol-keyed Hash (per-criterion globals), or a Hash mixing Symbol keys with String / Regexp keys to declare per-path overrides (#575).
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/simplecov/configuration/thresholds.rb', line 49 def minimum_coverage_by_file(coverage = nil) return @minimum_coverage_by_file ||= {} unless coverage coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric) defaults, overrides = partition_per_file_thresholds(coverage) Deprecation.warn("`SimpleCov.minimum_coverage_by_file` is deprecated. " \ "Replace it with:\n#{per_file_coverage_replacement(defaults, overrides)}") raise_on_invalid_coverage(defaults, "minimum_coverage_by_file") overrides.each_value { |criteria| raise_on_invalid_coverage(criteria, "minimum_coverage_by_file") } @minimum_coverage_by_file = defaults @minimum_coverage_by_file_overrides = overrides end |
#minimum_coverage_by_file_overrides ⇒ Hash[String | Regexp, coverage_thresholds]
65 66 67 |
# File 'lib/simplecov/configuration/thresholds.rb', line 65 def minimum_coverage_by_file_overrides @minimum_coverage_by_file_overrides ||= {} end |
#minimum_coverage_by_group ⇒ Hash[String, coverage_thresholds] #minimum_coverage_by_group(coverage) ⇒ Hash[String, coverage_thresholds]
69 70 71 72 73 74 75 76 77 |
# File 'lib/simplecov/configuration/thresholds.rb', line 69 def minimum_coverage_by_group(coverage = nil) return @minimum_coverage_by_group ||= {} unless coverage Deprecation.warn("`SimpleCov.minimum_coverage_by_group` is deprecated. " \ "Replace it with:\n#{per_group_coverage_replacement(coverage)}") @minimum_coverage_by_group = coverage.to_h do |group_name, group_coverage| [GroupNames.normalize(group_name), normalized_threshold(group_coverage, "minimum_coverage_by_group")] end end |
#minimum_possible_coverage_exceeded(coverage_option) ⇒ void
This method returns an undefined value.
115 116 117 |
# File 'lib/simplecov/configuration/thresholds.rb', line 115 def minimum_possible_coverage_exceeded(coverage_option) warn "The coverage you set for #{coverage_option} is greater than 100%" end |
#missed_per_file_replacement(counts) ⇒ String
45 46 47 48 49 |
# File 'lib/simplecov/configuration/missed_caps.rb', line 45 def missed_per_file_replacement(counts) counts = {primary_coverage => counts} if counts.is_a?(Numeric) counts.map { |criterion, cap| " coverage(#{criterion.inspect}) { maximum_missed #{cap}, per: :file }" } .join("\n") end |
#no_default_skips ⇒ Array[Filter[untyped]]
Order matters: call this before your own skip invocations.
96 97 98 |
# File 'lib/simplecov/configuration/filters.rb', line 96 def no_default_skips clear_filters end |
#nocov_token(nocov_token = nil) ⇒ String Also known as: skip_token
86 87 88 89 90 |
# File 'lib/simplecov/configuration/formatting.rb', line 86 def nocov_token(nocov_token = nil) Deprecation.warn("`SimpleCov.nocov_token` and `SimpleCov.skip_token` are deprecated. " \ "Replace with `# simplecov:disable` / `# simplecov:enable` block comments.") current_nocov_token(nocov_token) end |
#normalized_missed_caps(counts, setting) ⇒ missed_caps
31 32 33 34 35 36 |
# File 'lib/simplecov/configuration/missed_caps.rb', line 31 def normalized_missed_caps(counts, setting) counts = {primary_coverage => counts} if counts.is_a?(Numeric) counts.each_key { |criterion| raise_if_criterion_disabled(criterion) } counts.each_value { |cap| raise_on_invalid_missed_cap(cap, setting) } _ = counts end |
#normalized_threshold(coverage, setting) ⇒ coverage_thresholds
A bare Numeric targets the primary criterion, and the resulting per-criterion hash is validated before it is stored.
88 89 90 91 |
# File 'lib/simplecov/configuration/thresholds.rb', line 88 def normalized_threshold(coverage, setting) coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric) coverage.tap { |thresholds| raise_on_invalid_coverage(thresholds, setting) } end |
#parallel_tests(value = :__no_arg__) ⇒ Boolean?
Whether SimpleCov should auto-require the parallel_tests gem when it
sees TEST_ENV_NUMBER / PARALLEL_TEST_GROUPS in the environment.
Defaults to auto-detect (nil). See #1018.
33 34 35 36 37 |
# File 'lib/simplecov/configuration/merging.rb', line 33 def parallel_tests(value = :__no_arg__) return @parallel_tests if value.eql?(:__no_arg__) self.parallel_tests = _ = value end |
#parallel_tests=(value) ⇒ Object
39 40 41 |
# File 'lib/simplecov/configuration/merging.rb', line 39 def parallel_tests=(value) @parallel_tests = value end |
#parallel_wait_timeout(seconds = nil) ⇒ Integer
How long (in seconds) the reporting process waits for the remaining parallel-test workers to write their resultsets before it proceeds with a partial merge. Default is 60 seconds. Raise it when a slow worker routinely finishes well after the others, so its coverage is still included and the threshold checks aren't skipped against a partial total.
143 144 145 146 |
# File 'lib/simplecov/configuration/merging.rb', line 143 def parallel_wait_timeout(seconds = nil) self.parallel_wait_timeout = seconds @parallel_wait_timeout ||= 60 end |
#parallel_wait_timeout=(seconds) ⇒ Object
Anything but an Integer is ignored, the way the dual method always did.
149 150 151 |
# File 'lib/simplecov/configuration/merging.rb', line 149 def parallel_wait_timeout=(seconds) @parallel_wait_timeout = seconds if seconds.instance_of?(Integer) end |
#parallel_worker_environment? ⇒ Boolean
167 168 169 |
# File 'lib/simplecov/configuration/merging.rb', line 167 def parallel_worker_environment? ENV.key?("TEST_ENV_NUMBER") || ENV.key?("PARALLEL_TEST_GROUPS") end |
#parse_filter(filter_argument = nil, &filter_proc) ⇒ void
This method returns an undefined value.
102 103 104 105 106 107 108 |
# File 'lib/simplecov/configuration/filters.rb', line 102 def parse_filter(filter_argument = nil, &filter_proc) filter = filter_argument || filter_proc raise ArgumentError, "Please specify either a filter or a block to filter with" unless filter Filter.build_filter(filter) end |
#partition_per_file_thresholds(coverage) ⇒ [coverage_thresholds, Hash[String | Regexp, coverage_thresholds]]
Splits into Symbol-keyed criterion defaults and String/Regexp-keyed
per-path overrides, normalizing Numeric override values to
{primary_coverage => N} so downstream code has one shape to handle.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/simplecov/configuration/thresholds.rb', line 96 def partition_per_file_thresholds(coverage) coverage.each_key { |key| validate_per_file_key(key) } # The assertions restate what the partition predicate guarantees: Symbol # keys carry per-criterion Numeric defaults, the rest are paths. symbol_pairs, path_pairs = coverage.partition { |key, _| key.instance_of?(Symbol) } defaults = symbol_pairs.to_h #: coverage_thresholds raw = path_pairs.to_h #: Hash[String | Regexp, Numeric | coverage_thresholds] overrides = raw.transform_values { |value| value.is_a?(Numeric) ? {primary_coverage => value} : value } [defaults, overrides] end |
#per_file_coverage_replacement(defaults, overrides) ⇒ String
Renders the coverage configuration equivalent to a deprecated
minimum_coverage_by_file argument, so the deprecation warning can be
copy-pasted verbatim into the user's config.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/simplecov/configuration/thresholds.rb', line 122 def per_file_coverage_replacement(defaults, overrides) by_criterion = {} #: Hash[Symbol, Array[String]] defaults.each { |criterion, percent| (by_criterion[criterion] ||= []) << "minimum #{percent}, per: :file" } overrides.each do |target, criteria| criteria.each do |criterion, percent| (by_criterion[criterion] ||= []) << "minimum #{percent}, per: #{target.inspect}" end end render_coverage_blocks(by_criterion) end |
#per_group_coverage_replacement(coverage) ⇒ String
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/simplecov/configuration/thresholds.rb', line 133 def per_group_coverage_replacement(coverage) by_criterion = {} #: Hash[Symbol, Array[String]] coverage.each do |group_name, thresholds| normalized = (thresholds.is_a?(Numeric) ? {primary_coverage => thresholds} : thresholds) #: coverage_thresholds normalized.each do |criterion, percent| (by_criterion[criterion] ||= []) << "minimum #{percent}, per: group(#{group_name.inspect})" end end render_coverage_blocks(by_criterion) end |
#primary_coverage(criterion = nil) ⇒ criterion, :oneshot_line
28 29 30 31 32 33 34 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 28 def primary_coverage(criterion = nil) if criterion.nil? @primary_coverage ||= default_primary_coverage else self.primary_coverage = criterion end end |
#primary_coverage=(criterion) ⇒ criterion, :oneshot_line
36 37 38 39 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 36 def primary_coverage=(criterion) raise_if_criterion_disabled(criterion) @primary_coverage = criterion end |
#print_errors(value = :__no_arg__) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/simplecov/configuration/formatting.rb', line 60 def print_errors(value = :__no_arg__) return instance_variable_defined?(:@print_error_status) ? @print_error_status : true if value.eql?(:__no_arg__) self.print_errors = _ = value end |
#print_errors=(value) ⇒ Boolean
66 67 68 |
# File 'lib/simplecov/configuration/formatting.rb', line 66 def print_errors=(value) @print_error_status = value end |
#production_coverage(path = nil) ⇒ String?
The path to a production coverage store, the file a SimpleCov::Production
sink wrote. Relative paths resolve against SimpleCov.root. The store is
read at report time, and an unreadable or invalid file warns and leaves the
section out, because a missing night's data should not fail the suite that
measured the tests.
10 11 12 13 14 15 |
# File 'lib/simplecov/configuration/production.rb', line 10 def production_coverage(path = nil) return @production_coverage if path.nil? self.production_coverage = path @production_coverage end |
#production_coverage=(path) ⇒ String
17 18 19 20 21 |
# File 'lib/simplecov/configuration/production.rb', line 17 def production_coverage=(path) raise ConfigurationError, "production_coverage takes a path, got #{path.inspect}" unless path.is_a?(String) @production_coverage = File.(path, root) end |
#profiles ⇒ Profiles
73 74 75 |
# File 'lib/simplecov/configuration.rb', line 73 def profiles @profiles ||= Profiles.new end |
#project_name(new_name = nil) ⇒ String
Only a String renames, and a name already chosen survives anything else.
135 136 137 138 |
# File 'lib/simplecov/configuration.rb', line 135 def project_name(new_name = nil) @project_name = new_name if new_name.is_a?(String) @project_name ||= File.basename(root).capitalize.tr("_", " ") end |
#raise_if_branch_type_unsupported(type) ⇒ void
This method returns an undefined value.
56 57 58 59 60 61 62 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 56 def raise_if_branch_type_unsupported(type) return if IGNORABLE_BRANCH_TYPES.member?(type) raise ConfigurationError, "Unsupported branch type #{type.inspect} for `ignore_branches`. " \ "Supported values are #{IGNORABLE_BRANCH_TYPES.inspect}" end |
#raise_if_criterion_disabled(criterion) ⇒ void
This method returns an undefined value.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 121 def raise_if_criterion_disabled(criterion) if criterion.equal?(:eval) raise ConfigurationError, "Coverage criterion :eval only toggles measuring eval'd code; " \ "it cannot carry thresholds or serve as the primary criterion" end raise_if_criterion_unsupported(criterion) return if coverage_criterion_enabled?(criterion) raise ConfigurationError, "Coverage criterion #{criterion}, is disabled! " \ "Please enable it first through enable_coverage #{criterion} (if supported)" end |
#raise_if_criterion_unsupported(criterion) ⇒ void
This method returns an undefined value.
136 137 138 139 140 141 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 136 def raise_if_criterion_unsupported(criterion) return if SUPPORTED_COVERAGE_CRITERIA.member?(criterion) raise ConfigurationError, "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}" end |
#raise_if_method_type_unsupported(type) ⇒ void
This method returns an undefined value.
64 65 66 67 68 69 70 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 64 def raise_if_method_type_unsupported(type) return if IGNORABLE_METHOD_TYPES.member?(type) raise ConfigurationError, "Unsupported method type #{type.inspect} for `ignore_methods`. " \ "Supported values are #{IGNORABLE_METHOD_TYPES.inspect}" end |
#raise_on_invalid_coverage(coverage, coverage_setting) ⇒ void
This method returns an undefined value.
11 12 13 14 15 16 |
# File 'lib/simplecov/configuration/thresholds.rb', line 11 def raise_on_invalid_coverage(coverage, coverage_setting) coverage.each_key { |criterion| raise_if_criterion_disabled(criterion) } coverage.each_value do |percent| minimum_possible_coverage_exceeded(coverage_setting) if percent && percent > 100 end end |
#raise_on_invalid_missed_cap(cap, setting) ⇒ void
This method returns an undefined value.
38 39 40 41 42 43 |
# File 'lib/simplecov/configuration/missed_caps.rb', line 38 def raise_on_invalid_missed_cap(cap, setting) return if cap.instance_of?(Integer) && cap >= 0 raise ConfigurationError, "#{setting} takes a non-negative integer count of misses, got #{cap.inspect}" end |
#refuse_coverage_drop(*criteria) ⇒ coverage_thresholds
79 80 81 82 |
# File 'lib/simplecov/configuration/thresholds.rb', line 79 def refuse_coverage_drop(*criteria) criteria = coverage_criteria if criteria.empty? maximum_coverage_drop(criteria.to_h { |c| [c, 0] }) end |
#remove_filter(filter_argument) ⇒ Boolean
reject! answers nil when it rejected nothing, which is the whole of
"was anything removed".
84 85 86 87 88 89 |
# File 'lib/simplecov/configuration/filters.rb', line 84 def remove_filter(filter_argument) rejected = filters.reject! do |filter| filter.respond_to?(:filter_argument) && filter.filter_argument.eql?(filter_argument) end !rejected.nil? end |
#render_coverage_blocks(by_criterion) ⇒ String
144 145 146 147 148 |
# File 'lib/simplecov/configuration/thresholds.rb', line 144 def render_coverage_blocks(by_criterion) by_criterion.map do |criterion, statements| " coverage(#{criterion.inspect}) { #{statements.join("; ")} }" end.join("\n") end |
#require_html_formatter(name) ⇒ void
This method returns an undefined value.
formats :html has to work in a process that never required the HTML
formatter, which under SIMPLECOV_NO_DEFAULTS nothing else has.
124 125 126 127 |
# File 'lib/simplecov/configuration/formatting.rb', line 124 def require_html_formatter(name) path = LAZY_FORMAT_REQUIRES[name] require_relative(path) if path end |
#resolve_criterion_variant(criterion, oneshot) ⇒ criterion, ...
40 41 42 43 44 45 46 |
# File 'lib/simplecov/configuration/coverage.rb', line 40 def resolve_criterion_variant(criterion, oneshot) return criterion unless oneshot raise ConfigurationError, "`oneshot: true` is only valid for `coverage :line`" unless criterion.equal?(:line) ONESHOT_LINE_COVERAGE_CRITERION end |
#resolve_format(name) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/simplecov/configuration/formatting.rb', line 108 def resolve_format(name) return name unless name.instance_of?(Symbol) constant = BUILT_IN_FORMATS[name] unless constant raise ConfigurationError, "Unknown format #{name.inspect}. Built-in formats are :html, :json, :simple, and :baseline; " \ "pass a formatter class or instance for anything else." end require_html_formatter(name) Formatter.const_get(constant) end |
#root(root = nil) ⇒ String
7 8 9 10 11 12 |
# File 'lib/simplecov/configuration.rb', line 7 def root(root = nil) return @root if instance_variable_defined?(:@root) && root.nil? self.root = root @root end |
#root=(root) ⇒ String
nil means the working directory, the default the reader would have derived.
15 16 17 18 |
# File 'lib/simplecov/configuration.rb', line 15 def root=(root) @coverage_path = nil unless @coverage_path_explicit # invalidate cache @root = File.(root || Dir.getwd) end |
#skip(filter_argument = nil) ⇒ void
This method returns an undefined value.
Drop matching files from the coverage report. The inverse of cover.
Accepts a String (path-segment substring), Regexp, block predicate, or
Array of any of those.
71 72 73 |
# File 'lib/simplecov/configuration/filters.rb', line 71 def skip(filter_argument = nil, &) filters << parse_filter(filter_argument, &) end |
#source_in_json(value = :__no_arg__) ⇒ Boolean
70 71 72 73 74 |
# File 'lib/simplecov/configuration/formatting.rb', line 70 def source_in_json(value = :__no_arg__) return instance_variable_defined?(:@source_in_json) ? @source_in_json : true if value.eql?(:__no_arg__) self.source_in_json = _ = value end |
#source_in_json=(value) ⇒ Boolean
76 77 78 |
# File 'lib/simplecov/configuration/formatting.rb', line 76 def source_in_json=(value) @source_in_json = value end |
#store_ignored_branches(types) ⇒ Array[Symbol]
Variadic semantics: multiple calls union, duplicates are no-ops, unknown tokens raise.
44 45 46 47 48 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 44 def store_ignored_branches(types) types.each { |type| raise_if_branch_type_unsupported(type) } ignored_branches.concat(types).uniq! ignored_branches end |
#store_ignored_methods(types) ⇒ Array[Symbol]
50 51 52 53 54 |
# File 'lib/simplecov/configuration/ignored_entries.rb', line 50 def store_ignored_methods(types) types.each { |type| raise_if_method_type_unsupported(type) } ignored_methods.concat(types).uniq! ignored_methods end |
#store_maximum_missed_per_file(criterion, count, target) ⇒ void
This method returns an undefined value.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/simplecov/configuration/coverage.rb', line 60 def store_maximum_missed_per_file(criterion, count, target) raise_if_criterion_disabled(criterion) raise_on_invalid_missed_cap(count, "maximum_missed_per_file") return maximum_missed_per_file[criterion] = count if target.nil? unless target.is_a?(String) || target.is_a?(Regexp) raise ConfigurationError, "`only:` must be a String path or Regexp, got #{target.inspect}" end (maximum_missed_per_file_overrides[target] ||= {})[criterion] = count end |
#store_minimum_per_file(criterion, percent, target) ⇒ void
This method returns an undefined value.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/simplecov/configuration/coverage.rb', line 72 def store_minimum_per_file(criterion, percent, target) raise_on_invalid_coverage({criterion => percent}, "minimum_coverage_by_file") return minimum_coverage_by_file[criterion] = percent if target.nil? unless target.is_a?(String) || target.is_a?(Regexp) raise ConfigurationError, "`only:` must be a String path or Regexp, got #{target.inspect}" end (minimum_coverage_by_file_overrides[target] ||= {})[criterion] = percent end |
#store_minimum_per_group(criterion, percent, group_name) ⇒ void
This method returns an undefined value.
83 84 85 86 87 88 |
# File 'lib/simplecov/configuration/coverage.rb', line 83 def store_minimum_per_group(criterion, percent, group_name) raise_on_invalid_coverage({criterion => percent}, "minimum_coverage_by_group") # Normalized like `group` does, so `per: group(:Models)` finds the group # defined as `group "Models"` at check time. (minimum_coverage_by_group[GroupNames.normalize(group_name)] ||= {})[criterion] = percent end |
#store_missed_cap(setting, criterion, count) ⇒ void
This method returns an undefined value.
54 55 56 57 58 |
# File 'lib/simplecov/configuration/coverage.rb', line 54 def store_missed_cap(setting, criterion, count) raise_if_criterion_disabled(criterion) raise_on_invalid_missed_cap(count, setting) public_send(setting)[criterion] = count end |
#store_overall_threshold(setting, criterion, percent) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
49 50 51 52 |
# File 'lib/simplecov/configuration/coverage.rb', line 49 def store_overall_threshold(setting, criterion, percent) raise_on_invalid_coverage({criterion => percent}, setting) public_send(setting)[criterion] = percent end |
#track_files(glob) ⇒ String?
37 38 39 40 41 |
# File 'lib/simplecov/configuration/filters.rb', line 37 def track_files(glob) Deprecation.warn("`SimpleCov.track_files` is deprecated. " \ "#{track_files_replacement_hint(glob)}") @tracked_files = glob end |
#track_files_replacement_hint(glob) ⇒ String
track_files(nil) is the documented way to clear a previously-set glob,
but cover(nil) raises ConfigurationError, so don't point users at it.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/simplecov/configuration/filters.rb', line 45 def track_files_replacement_hint(glob) if glob.nil? "Replace with `SimpleCov.cover_filters.clear` — clearing the inclusion list." else "Replace with `SimpleCov.cover #{glob.inspect}` — `cover` includes unloaded files on disk " \ "(the historical `track_files` behavior) and also restricts the report to the matching set. " \ "If you want to keep additional files outside #{glob.inspect} in the report, pass every " \ "directory you care about, e.g. `cover #{glob.inspect}, \"app/**/*.rb\"`." end end |
#track_tests(enabled = nil, granularity: nil) ⇒ Boolean
Enables recording of which test covered which line. Off by default:
sampling coverage around every test costs run time, and the recorded map
costs space in .resultset.json. RSpec examples and Minitest tests are
wrapped automatically; other runners wrap their own units of work with
SimpleCov.track_test. A bare track_tests enables, and only an explicit
track_tests false turns it back off.
granularity decides what one recorded context stands for: a test
(:test, the default) or a whole test file (:file). File granularity is
the batching lever for suites where per-test sampling costs too much.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simplecov/configuration/test_tracking.rb', line 17 def track_tests(enabled = nil, granularity: nil) if granularity && !TRACK_TESTS_GRANULARITIES.include?(granularity) raise ConfigurationError, "Unsupported track_tests granularity #{granularity.inspect}, " \ "supported values are #{TRACK_TESTS_GRANULARITIES.inspect}" end @track_tests_granularity = granularity if granularity @track_tests = enabled.nil? || enabled end |
#track_tests? ⇒ Boolean
28 29 30 |
# File 'lib/simplecov/configuration/test_tracking.rb', line 28 def track_tests? !!@track_tests end |
#track_tests_granularity ⇒ Symbol
32 33 34 |
# File 'lib/simplecov/configuration/test_tracking.rb', line 32 def track_tests_granularity @track_tests_granularity || :test end |
#tracked_files ⇒ String?
Nil until cover names a glob: an unset ivar reads as nil, so the absence
needs no guard of its own.
58 59 60 |
# File 'lib/simplecov/configuration/filters.rb', line 58 def tracked_files @tracked_files end |
#use_merging(use = nil) ⇒ Boolean
100 101 102 103 104 |
# File 'lib/simplecov/configuration/merging.rb', line 100 def use_merging(use = nil) Deprecation.warn("`SimpleCov.use_merging` is deprecated. " \ "Replace with `SimpleCov.merging` (same value, same behavior).") merging(use) end |
#validate_coverage_criteria! ⇒ void
This method returns an undefined value.
54 55 56 57 58 59 60 |
# File 'lib/simplecov/configuration/coverage_criteria.rb', line 54 def validate_coverage_criteria! return unless coverage_criteria.empty? raise ConfigurationError, "At least one coverage criterion must be enabled. " \ "Re-enable one with `enable_coverage :line`, `:branch`, or `:method`." end |
#validate_per_file_key(key) ⇒ void
This method returns an undefined value.
107 108 109 110 111 112 113 |
# File 'lib/simplecov/configuration/thresholds.rb', line 107 def validate_per_file_key(key) # Symbols have no subclasses; paths and patterns may. return if key.instance_of?(Symbol) || key.is_a?(String) || key.is_a?(Regexp) raise ConfigurationError, "minimum_coverage_by_file keys must be Symbol (criterion), String, or Regexp; got #{key.inspect}" end |
#validate_test_tracking! ⇒ void
This method returns an undefined value.
:oneshot_line does not produce: a line reports only its first hit ever,
so every test after the first would show no delta.
39 40 41 42 43 44 45 46 |
# File 'lib/simplecov/configuration/test_tracking.rb', line 39 def validate_test_tracking! return unless track_tests? return if coverage_criterion_enabled?(DEFAULT_COVERAGE_CRITERION) raise ConfigurationError, "`track_tests` needs line coverage with execution counts. " \ "Enable it with `enable_coverage :line` (`:oneshot_line` cannot record per-test data)." end |
#view_coverage? ⇒ Boolean
False when eval coverage couldn't be enabled, where cover_views has
already warned and the templates would come back empty rather than at 0%.
33 34 35 |
# File 'lib/simplecov/configuration/view_coverage.rb', line 33 def view_coverage? !view_globs.nil? && coverage_for_eval_enabled? end |
#view_globs ⇒ Array[String]?
Nil rather than an empty Array when cover_views was never called, so
"not asked for" stays distinguishable from "asked for, with nothing to
match".
27 28 29 |
# File 'lib/simplecov/configuration/view_coverage.rb', line 27 def view_globs @view_globs end |
#warn_about_inferred_finalize_merge ⇒ void
This method returns an undefined value.
181 182 183 184 185 186 187 |
# File 'lib/simplecov/configuration/merging.rb', line 181 def warn_about_inferred_finalize_merge return if @finalize_merge_inference_warned return unless print_errors @finalize_merge_inference_warned = true warn Color.colorize(inferred_finalize_merge_warning, :yellow) end |