You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow per-path overrides in minimum_coverage_by_file
`minimum_coverage_by_file` now accepts String and Regexp keys alongside
the existing Symbol-keyed per-criterion defaults. String keys match the
project-relative path exactly, except those ending in `/`, which match
as a directory prefix; Regexp keys are tested against the project path.
Per-path values may be a Numeric (primary criterion) or a per-criterion
Hash, e.g. `minimum_coverage_by_file line: 70, 'app/critical.rb' => 100`.
For each file, the effective threshold is the Symbol-keyed defaults
merged with every matching override — later overrides win per criterion,
and any override wins over the default for the same criterion. A file
that matches no override keeps the global defaults, so adding an
override only ever raises the bar for the files it touches. The new
overrides surface in `coverage.json` under the existing
`errors.minimum_coverage_by_file` block.
The public getter `SimpleCov.minimum_coverage_by_file` still returns
just the Symbol-keyed defaults, preserving the existing return shape;
a new `SimpleCov.minimum_coverage_by_file_overrides` reader exposes the
per-path map. The setter, `CoverageViolations.minimum_by_file`, the
`MinimumCoverageByFileCheck` constructor, the `CoverageLimits` struct,
and the JSON formatter were updated to carry overrides through.
Resolves#575.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ Unreleased
15
15
*`# :nocov:` toggle comments (and the configurable `SimpleCov.nocov_token` / `SimpleCov.skip_token`) are deprecated in favor of the new `# simplecov:disable` / `# simplecov:enable` directives. Each file that still uses `# :nocov:` emits a one-time deprecation warning to stderr at load time pointing at the recommended replacement, and any call to `SimpleCov.nocov_token` or `SimpleCov.skip_token` (getter or setter) likewise warns. The directive will be removed in a future release.
16
16
17
17
## Enhancements
18
+
*`SimpleCov.minimum_coverage_by_file` now accepts per-path overrides alongside the existing per-criterion defaults: pass String or Regexp keys to declare file- or directory-specific thresholds, e.g. `minimum_coverage_by_file line: 70, 'app/mailers/request_mailer.rb' => 100`. A String ending in `/` matches as a directory prefix; otherwise it must equal the project-relative path. Regexp keys match against the project-relative path. Per-path values may be a Numeric (primary criterion) or a per-criterion Hash; for each file the effective threshold is the defaults merged with any matching overrides (later overrides win per criterion, overrides win over defaults). The new overrides surface in `coverage.json` under the existing `errors.minimum_coverage_by_file` block. See #575.
18
19
* Added `SimpleCov.maximum_coverage` (and the convenience `SimpleCov.expected_coverage`, which sets `minimum_coverage` and `maximum_coverage` to the same value) so the suite can be pinned to an exact coverage figure. A drop fails per the minimum; an unexpected increase also fails, prompting you to bump the threshold up rather than silently absorbing the improvement. Accepts the same Numeric / per-criterion Hash forms as `minimum_coverage`. Exits with status 4 (`SimpleCov::ExitCodes::MAXIMUM_COVERAGE`) when violated, and surfaces in `coverage.json` under `errors.maximum_coverage`. Comparisons floor the actual percent to two decimal places, so `expected_coverage 95.42` still passes when the actual is e.g. 95.4287. See #187.
19
20
* Added a bundled `strict` profile (`SimpleCov.start "strict"`) that enables line, branch, and method coverage and pins the minimum threshold for each at 100%. Drops to line-only on engines without branch/method support (JRuby). See #1061.
20
21
*`SimpleCov.coverage_path` is now explicitly settable rather than always computed from `SimpleCov.root + SimpleCov.coverage_dir`. Setting it pins the report destination regardless of later `root` / `coverage_dir` changes — useful for out-of-tree build directories (CMake/CTest etc.) where the coverage report doesn't live under the source root. See #716.
You can also raise the bar for specific files or directories by passing String or Regexp keys alongside the Symbol-keyed defaults. The String form does an exact match against the project-relative path, or a directory-prefix match when it ends in `/`; the Regexp form is matched against the project-relative path. Per-path values may be a single number (applied to the primary criterion) or a per-criterion Hash. For each file, the effective threshold is the defaults merged with any matching overrides — later overrides win per criterion, and overrides themselves win over defaults. See #575.
937
+
938
+
```ruby
939
+
# 70% line coverage everywhere — but require 100% for one critical file
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (100.00%) in lib/faked_project/framework_specific.rb."
87
+
And the output should contain "SimpleCov failed with exit 2"
88
+
89
+
Scenario: Per-path override does not flag files that pass the default but not the override
90
+
# framework_specific.rb is at 75% — passes the default 70%; some_class.rb is
91
+
# at 80% — passes both. The directory-prefix override raises the bar to 90%
92
+
# for lib/faked_project/, so framework_specific.rb fails its override.
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (90.00%) in lib/faked_project/framework_specific.rb."
105
+
And the output should contain "SimpleCov failed with exit 2"
106
+
107
+
Scenario: Per-path override that no file matches has no effect
0 commit comments