simplecov 0.22.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +173 -875
- data/exe/simplecov +8 -0
- data/lib/minitest/simplecov_plugin.rb +18 -7
- data/lib/simplecov/atomic_file.rb +67 -0
- data/lib/simplecov/autostart.rb +9 -0
- data/lib/simplecov/baseline/parser.rb +58 -0
- data/lib/simplecov/baseline.rb +170 -0
- data/lib/simplecov/cli/affected/changed_files.rb +57 -0
- data/lib/simplecov/cli/affected/selection.rb +117 -0
- data/lib/simplecov/cli/affected.rb +148 -0
- data/lib/simplecov/cli/annotations.rb +166 -0
- data/lib/simplecov/cli/badge/svg.rb +70 -0
- data/lib/simplecov/cli/badge.rb +62 -0
- data/lib/simplecov/cli/clean.rb +86 -0
- data/lib/simplecov/cli/command_helpers.rb +91 -0
- data/lib/simplecov/cli/completions/scripts.rb +114 -0
- data/lib/simplecov/cli/completions.rb +83 -0
- data/lib/simplecov/cli/coverage.rb +83 -0
- data/lib/simplecov/cli/coverage_file.rb +109 -0
- data/lib/simplecov/cli/dead_code/output.rb +100 -0
- data/lib/simplecov/cli/dead_code.rb +139 -0
- data/lib/simplecov/cli/diff/output.rb +45 -0
- data/lib/simplecov/cli/diff.rb +115 -0
- data/lib/simplecov/cli/dotfile.rb +156 -0
- data/lib/simplecov/cli/git.rb +41 -0
- data/lib/simplecov/cli/history/output.rb +135 -0
- data/lib/simplecov/cli/history.rb +67 -0
- data/lib/simplecov/cli/merge.rb +115 -0
- data/lib/simplecov/cli/open.rb +45 -0
- data/lib/simplecov/cli/patch/changed_lines.rb +149 -0
- data/lib/simplecov/cli/patch/output.rb +151 -0
- data/lib/simplecov/cli/patch.rb +175 -0
- data/lib/simplecov/cli/ratchet/output.rb +44 -0
- data/lib/simplecov/cli/ratchet.rb +83 -0
- data/lib/simplecov/cli/report.rb +91 -0
- data/lib/simplecov/cli/run.rb +35 -0
- data/lib/simplecov/cli/serve/report_preparer.rb +30 -0
- data/lib/simplecov/cli/serve/static_file_handler.rb +128 -0
- data/lib/simplecov/cli/serve.rb +88 -0
- data/lib/simplecov/cli/show/annotator.rb +87 -0
- data/lib/simplecov/cli/show/sweep.rb +36 -0
- data/lib/simplecov/cli/show.rb +133 -0
- data/lib/simplecov/cli/status/facts.rb +87 -0
- data/lib/simplecov/cli/status.rb +93 -0
- data/lib/simplecov/cli/tests/redundancy.rb +78 -0
- data/lib/simplecov/cli/tests.rb +148 -0
- data/lib/simplecov/cli/uncovered/misses.rb +33 -0
- data/lib/simplecov/cli/uncovered.rb +127 -0
- data/lib/simplecov/cli/usage.rb +153 -0
- data/lib/simplecov/cli/watch/live_report.rb +73 -0
- data/lib/simplecov/cli/watch/narrator.rb +55 -0
- data/lib/simplecov/cli/watch/poller.rb +45 -0
- data/lib/simplecov/cli/watch/session.rb +134 -0
- data/lib/simplecov/cli/watch/test_plan.rb +43 -0
- data/lib/simplecov/cli/watch.rb +85 -0
- data/lib/simplecov/cli.rb +114 -0
- data/lib/simplecov/color.rb +65 -0
- data/lib/simplecov/combine/branches_combiner.rb +44 -21
- data/lib/simplecov/combine/coverage_accumulator.rb +175 -0
- data/lib/simplecov/combine/identity_interner.rb +27 -0
- data/lib/simplecov/combine/interned_counts.rb +28 -0
- data/lib/simplecov/combine/lines_combiner.rb +35 -29
- data/lib/simplecov/combine/methods_combiner.rb +48 -0
- data/lib/simplecov/combine/results_combiner.rb +9 -49
- data/lib/simplecov/combine.rb +0 -24
- data/lib/simplecov/command_guesser.rb +99 -42
- data/lib/simplecov/configuration/baseline.rb +31 -0
- data/lib/simplecov/configuration/coverage.rb +184 -0
- data/lib/simplecov/configuration/coverage_criteria.rb +143 -0
- data/lib/simplecov/configuration/deprecations.rb +21 -0
- data/lib/simplecov/configuration/eval_coverage.rb +37 -0
- data/lib/simplecov/configuration/filters.rb +131 -0
- data/lib/simplecov/configuration/formatting.rb +129 -0
- data/lib/simplecov/configuration/groups.rb +48 -0
- data/lib/simplecov/configuration/history.rb +44 -0
- data/lib/simplecov/configuration/ignored_entries.rb +72 -0
- data/lib/simplecov/configuration/merging.rb +197 -0
- data/lib/simplecov/configuration/missed_caps.rb +51 -0
- data/lib/simplecov/configuration/production.rb +23 -0
- data/lib/simplecov/configuration/test_tracking.rb +48 -0
- data/lib/simplecov/configuration/thresholds.rb +150 -0
- data/lib/simplecov/configuration/view_coverage.rb +37 -0
- data/lib/simplecov/configuration.rb +100 -443
- data/lib/simplecov/configuration_error.rb +5 -0
- data/lib/simplecov/context_map/union.rb +81 -0
- data/lib/simplecov/context_map.rb +187 -0
- data/lib/simplecov/coverage_json.rb +21 -0
- data/lib/simplecov/coverage_statistics.rb +24 -28
- data/lib/simplecov/coverage_violations.rb +254 -0
- data/lib/simplecov/current_run.rb +61 -0
- data/lib/simplecov/defaults.rb +20 -28
- data/lib/simplecov/deprecation.rb +63 -0
- data/lib/simplecov/directive/erb.rb +44 -0
- data/lib/simplecov/directive/haml.rb +33 -0
- data/lib/simplecov/directive/indented_template.rb +37 -0
- data/lib/simplecov/directive/slim.rb +35 -0
- data/lib/simplecov/directive/template.rb +29 -0
- data/lib/simplecov/directive.rb +152 -0
- data/lib/simplecov/exit_codes/baseline_check.rb +46 -0
- data/lib/simplecov/exit_codes/check.rb +39 -0
- data/lib/simplecov/exit_codes/exit_code_handling.rb +24 -5
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +17 -67
- data/lib/simplecov/exit_codes/maximum_missed_check.rb +26 -0
- data/lib/simplecov/exit_codes/maximum_missed_per_file_check.rb +34 -0
- data/lib/simplecov/exit_codes/maximum_overall_coverage_check.rb +27 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +20 -38
- data/lib/simplecov/exit_codes/minimum_coverage_by_group_check.rb +28 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +37 -34
- data/lib/simplecov/exit_codes.rb +26 -0
- data/lib/simplecov/exit_handling.rb +163 -0
- data/lib/simplecov/file_list.rb +63 -48
- data/lib/simplecov/filter.rb +98 -42
- data/lib/simplecov/formatter/base.rb +100 -0
- data/lib/simplecov/formatter/baseline_formatter.rb +98 -0
- data/lib/simplecov/formatter/coverage_json_writer.rb +95 -0
- data/lib/simplecov/formatter/html_formatter/public/index.html +93 -0
- data/lib/simplecov/formatter/html_formatter/viewer_data_validator.rb +153 -0
- data/lib/simplecov/formatter/html_formatter.rb +88 -0
- data/lib/simplecov/formatter/json_formatter/errors_formatter.rb +122 -0
- data/lib/simplecov/formatter/json_formatter/production_section_formatter.rb +48 -0
- data/lib/simplecov/formatter/json_formatter/result_hash_formatter.rb +132 -0
- data/lib/simplecov/formatter/json_formatter/source_file_formatter.rb +97 -0
- data/lib/simplecov/formatter/json_formatter.rb +40 -0
- data/lib/simplecov/formatter/multi_formatter.rb +8 -10
- data/lib/simplecov/formatter/simple_formatter.rb +12 -15
- data/lib/simplecov/formatter.rb +21 -1
- data/lib/simplecov/group_names.rb +33 -0
- data/lib/simplecov/history.rb +115 -0
- data/lib/simplecov/last_run.rb +16 -5
- data/lib/simplecov/lines_classifier.rb +67 -19
- data/lib/simplecov/load_global_config.rb +12 -4
- data/lib/simplecov/parallel_adapters/base.rb +50 -0
- data/lib/simplecov/parallel_adapters/generic.rb +33 -0
- data/lib/simplecov/parallel_adapters/parallel_tests.rb +72 -0
- data/lib/simplecov/parallel_adapters.rb +54 -0
- data/lib/simplecov/parallel_coordination.rb +124 -0
- data/lib/simplecov/parallel_result_merger/worker_payload.rb +33 -0
- data/lib/simplecov/parallel_result_merger.rb +171 -0
- data/lib/simplecov/process.rb +34 -12
- data/lib/simplecov/production/error.rb +11 -0
- data/lib/simplecov/production/file_sink.rb +130 -0
- data/lib/simplecov/production.rb +249 -0
- data/lib/simplecov/profiles/bundler_filter.rb +1 -1
- data/lib/simplecov/profiles/hidden_filter.rb +1 -1
- data/lib/simplecov/profiles/rails.rb +13 -10
- data/lib/simplecov/profiles/root_filter.rb +2 -5
- data/lib/simplecov/profiles/strict.rb +22 -0
- data/lib/simplecov/profiles/test_frameworks.rb +1 -4
- data/lib/simplecov/profiles.rb +26 -19
- data/lib/simplecov/report_deferral.rb +45 -0
- data/lib/simplecov/report_stamp.rb +25 -0
- data/lib/simplecov/result/filter_config.rb +19 -0
- data/lib/simplecov/result/missing_source_files_reporter.rb +48 -0
- data/lib/simplecov/result/serialization.rb +43 -0
- data/lib/simplecov/result/source_file_builder.rb +46 -0
- data/lib/simplecov/result.rb +123 -47
- data/lib/simplecov/result_adapter.rb +130 -11
- data/lib/simplecov/result_merger/contexts.rb +22 -0
- data/lib/simplecov/result_merger/legacy_format_adapter.rb +24 -0
- data/lib/simplecov/result_merger/resultset_file.rb +67 -0
- data/lib/simplecov/result_merger/resultset_run_identity.rb +65 -0
- data/lib/simplecov/result_merger/resultset_store.rb +62 -0
- data/lib/simplecov/result_merger/unloaded_files.rb +95 -0
- data/lib/simplecov/result_merger.rb +120 -124
- data/lib/simplecov/result_processing.rb +188 -0
- data/lib/simplecov/run_identity.rb +75 -0
- data/lib/simplecov/simulate_coverage.rb +72 -17
- data/lib/simplecov/source_file/branch.rb +8 -35
- data/lib/simplecov/source_file/branch_builder.rb +95 -0
- data/lib/simplecov/source_file/builder_context.rb +28 -0
- data/lib/simplecov/source_file/line.rb +17 -32
- data/lib/simplecov/source_file/line_builder.rb +37 -0
- data/lib/simplecov/source_file/method.rb +54 -0
- data/lib/simplecov/source_file/method_builder.rb +51 -0
- data/lib/simplecov/source_file/ruby_data_parser.rb +103 -0
- data/lib/simplecov/source_file/skip_chunks.rb +72 -0
- data/lib/simplecov/source_file/source_loader.rb +89 -0
- data/lib/simplecov/source_file/statistics.rb +76 -0
- data/lib/simplecov/source_file.rb +64 -260
- data/lib/simplecov/static_coverage_extractor/condition_folding.rb +155 -0
- data/lib/simplecov/static_coverage_extractor/location_conventions.rb +191 -0
- data/lib/simplecov/static_coverage_extractor/method_collector.rb +45 -0
- data/lib/simplecov/static_coverage_extractor/prism_compat.rb +46 -0
- data/lib/simplecov/static_coverage_extractor/value_position.rb +61 -0
- data/lib/simplecov/static_coverage_extractor/visitor.rb +163 -0
- data/lib/simplecov/static_coverage_extractor.rb +78 -0
- data/lib/simplecov/test_tracker/accessors.rb +34 -0
- data/lib/simplecov/test_tracker/constant_watch.rb +49 -0
- data/lib/simplecov/test_tracker/delta.rb +69 -0
- data/lib/simplecov/test_tracker/framework_hooks.rb +130 -0
- data/lib/simplecov/test_tracker.rb +162 -0
- data/lib/simplecov/unloaded_file_injector.rb +62 -0
- data/lib/simplecov/useless_results_remover.rb +17 -7
- data/lib/simplecov/version.rb +1 -1
- data/lib/simplecov/view_coverage/template_compiler.rb +83 -0
- data/lib/simplecov/view_coverage.rb +55 -0
- data/lib/simplecov-html.rb +5 -0
- data/lib/simplecov.rb +143 -394
- data/lib/simplecov_json_formatter.rb +5 -0
- data/man/simplecov.1 +354 -0
- data/sig/simplecov.rbs +1710 -0
- metadata +183 -61
- data/CHANGELOG.md +0 -191
- data/doc/alternate-formatters.md +0 -71
- data/doc/commercial-services.md +0 -25
- data/doc/editor-integration.md +0 -18
- data/lib/simplecov/combine/files_combiner.rb +0 -24
- data/lib/simplecov/default_formatter.rb +0 -20
data/README.md
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
1
|
-
SimpleCov [](https://badge.fury.io/rb/simplecov) [][
|
|
1
|
+
SimpleCov [](https://badge.fury.io/rb/simplecov) [][ci] [](https://github.com/simplecov-ruby/simplecov/actions/workflows/lint.yml) [](https://github.com/simplecov-ruby/simplecov/actions/workflows/typecheck.yml) [](https://github.com/simplecov-ruby/simplecov/actions/workflows/mutation.yml) [](https://codeclimate.com/github/simplecov-ruby/simplecov/maintainability)
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
4
|
**Code coverage for Ruby**
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* [API documentation]
|
|
8
|
-
* [Changelog]
|
|
9
|
-
* [Rubygem]
|
|
10
|
-
* [Continuous Integration]
|
|
11
|
-
|
|
12
|
-
[Coverage]: https://ruby-doc.org/stdlib/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
|
|
13
|
-
[Source Code]: https://github.com/simplecov-ruby/simplecov "Source Code @ GitHub"
|
|
14
|
-
[API documentation]: http://rubydoc.info/gems/simplecov/frames "RDoc API Documentation at Rubydoc.info"
|
|
15
|
-
[Configuration]: http://rubydoc.info/gems/simplecov/SimpleCov/Configuration "Configuration options API documentation"
|
|
16
|
-
[Changelog]: https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md "Project Changelog"
|
|
17
|
-
[Rubygem]: http://rubygems.org/gems/simplecov "SimpleCov @ rubygems.org"
|
|
18
|
-
[Continuous Integration]: https://github.com/simplecov-ruby/simplecov/actions?query=workflow%3Astable "SimpleCov is built around the clock by github.com"
|
|
19
|
-
[Dependencies]: https://gemnasium.com/simplecov-ruby/simplecov "SimpleCov dependencies on Gemnasium"
|
|
20
|
-
[simplecov-html]: https://github.com/simplecov-ruby/simplecov-html "SimpleCov HTML Formatter Source Code @ GitHub"
|
|
21
|
-
|
|
22
|
-
SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Coverage][Coverage] library to gather code
|
|
23
|
-
coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format,
|
|
24
|
-
and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of
|
|
25
|
-
code.
|
|
26
|
-
SimpleCov/Coverage track covered ruby code, gathering coverage for common templating solutions like erb, slim and haml is not supported.
|
|
27
|
-
|
|
28
|
-
In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features,
|
|
29
|
-
etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your
|
|
30
|
-
report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
|
|
31
|
-
|
|
32
|
-
The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and
|
|
33
|
-
configured automatically when you launch SimpleCov. If you're curious, you can find it [on GitHub, too][simplecov-html].
|
|
6
|
+
[ci]: https://github.com/simplecov-ruby/simplecov/actions?query=workflow%3Astable
|
|
34
7
|
|
|
8
|
+
SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in
|
|
9
|
+
Coverage][Coverage] library to gather coverage data, but makes processing the
|
|
10
|
+
results much easier by providing a clean API to filter, group, merge, format,
|
|
11
|
+
and display them. You can get a full coverage setup running in a couple of
|
|
12
|
+
lines of code.
|
|
35
13
|
|
|
36
|
-
|
|
14
|
+
[Coverage]: https://docs.ruby-lang.org/en/master/Coverage.html
|
|
37
15
|
|
|
38
|
-
|
|
16
|
+
SimpleCov tracks covered Ruby code.
|
|
39
17
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
18
|
+
In most cases you'll want overall coverage results spanning all of your tests
|
|
19
|
+
(unit, integration, etc.). SimpleCov handles this automatically by caching and
|
|
20
|
+
merging results as it generates reports, so a report reflects coverage across
|
|
21
|
+
your whole test suite and gives you a truer picture of your blank spots.
|
|
43
22
|
|
|
44
|
-
|
|
23
|
+
SimpleCov bundles two formatters: the default HTML formatter (which renders the
|
|
24
|
+
browsable report) and a JSON formatter. Both were once separate gems
|
|
25
|
+
(`simplecov-html` and `simplecov_json_formatter`) but are now built into
|
|
26
|
+
SimpleCov and configured automatically when you launch it. A wide variety of
|
|
27
|
+
[alternate formatters](docs/Alternate_Formatters.md) are distributed as gems.
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
on Google Groups"
|
|
29
|
+
## Getting started
|
|
48
30
|
|
|
49
|
-
Getting started
|
|
50
|
-
---------------
|
|
51
31
|
1. Add SimpleCov to your `Gemfile` and `bundle install`:
|
|
52
32
|
|
|
53
33
|
```ruby
|
|
54
34
|
gem 'simplecov', require: false, group: :test
|
|
55
35
|
```
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
|
|
37
|
+
2. Load and launch SimpleCov **at the very top** of your test helper, whether
|
|
38
|
+
that's `test/test_helper.rb`, `spec/spec_helper.rb`, `rails_helper.rb`, or
|
|
39
|
+
Cucumber's `features/support/env.rb`. SimpleCov doesn't care which framework
|
|
40
|
+
you run. It watches what code executes and reports on it, so the same two
|
|
41
|
+
lines work everywhere:
|
|
59
42
|
|
|
60
43
|
```ruby
|
|
61
44
|
require 'simplecov'
|
|
@@ -64,911 +47,226 @@ Getting started
|
|
|
64
47
|
# Previous content of test helper now starts here
|
|
65
48
|
```
|
|
66
49
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
This is especially true if you use anything that keeps your tests application loaded like spring, check out the **[spring section](#want-to-use-spring-with-simplecov)**.
|
|
50
|
+
> **Important:** `SimpleCov.start` **must** run **before any of your
|
|
51
|
+
> application code is required**. Otherwise SimpleCov (and the underlying
|
|
52
|
+
> Coverage library) can't track those files. This bites hardest with tools
|
|
53
|
+
> that keep your app loaded between runs, like Spring. See the
|
|
54
|
+
> [Spring section](docs/Troubleshooting.md#using-spring-with-simplecov).
|
|
73
55
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
to the top of `bin/rails`, but below the "shebang" line (`#! /usr/bin/env
|
|
81
|
-
ruby`) and after config/boot is required:
|
|
56
|
+
SimpleCov must run in the process you want to analyze. When you test a
|
|
57
|
+
server process (e.g. a JSON API) from a separate test process (e.g. via
|
|
58
|
+
Selenium) and want to see all the code the `rails server` executes, not just
|
|
59
|
+
the code in your test files, require SimpleCov in the server process. For
|
|
60
|
+
Rails, add this near the top of `bin/rails`, below the shebang and after
|
|
61
|
+
`config/boot` is required:
|
|
82
62
|
|
|
83
63
|
```ruby
|
|
84
64
|
if ENV['RAILS_ENV'] == 'test'
|
|
85
65
|
require 'simplecov'
|
|
86
66
|
SimpleCov.start 'rails'
|
|
87
|
-
puts "required simplecov"
|
|
88
67
|
end
|
|
89
68
|
```
|
|
90
69
|
|
|
91
|
-
3. Run your full test suite to see
|
|
92
|
-
4. After running your tests, open `coverage/index.html` in the browser of your choice. For example, in a Mac Terminal,
|
|
93
|
-
run the following command from your application's root directory:
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
open coverage/index.html
|
|
97
|
-
```
|
|
98
|
-
in a debian/ubuntu Terminal,
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
xdg-open coverage/index.html
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Note:** [This guide](https://dwheeler.com/essays/open-files-urls.html) can help if you're unsure which command your particular
|
|
105
|
-
operating system requires.
|
|
106
|
-
|
|
107
|
-
5. Add the following to your `.gitignore` file to ensure that coverage results
|
|
108
|
-
are not tracked by Git (optional):
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
echo coverage >> .gitignore
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on
|
|
115
|
-
profiles) that will get you started with groups for your Controllers, Models and Helpers. To use it, the
|
|
116
|
-
first two lines of your test_helper should be like this:
|
|
117
|
-
|
|
118
|
-
```ruby
|
|
119
|
-
require 'simplecov'
|
|
120
|
-
SimpleCov.start 'rails'
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Example output
|
|
124
|
-
|
|
125
|
-
**Coverage results report, fully browsable locally with sorting and much more:**
|
|
126
|
-
|
|
127
|
-

|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
**Source file coverage details view:**
|
|
70
|
+
3. Run your full test suite to see your application's coverage.
|
|
131
71
|
|
|
132
|
-
|
|
72
|
+
4. Open the HTML report in your default browser:
|
|
133
73
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Similarly to the usage with Test::Unit described above, the only thing you have to do is to add the SimpleCov
|
|
137
|
-
config to the very top of your Cucumber/RSpec/whatever setup file.
|
|
138
|
-
|
|
139
|
-
Add the setup code to the **top** of `features/support/env.rb` (for Cucumber) or `spec/spec_helper.rb` (for RSpec).
|
|
140
|
-
Other test frameworks should work accordingly, whatever their setup file may be:
|
|
141
|
-
|
|
142
|
-
```ruby
|
|
143
|
-
require 'simplecov'
|
|
144
|
-
SimpleCov.start 'rails'
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov
|
|
148
|
-
does not care what kind of framework it is running in; it just looks at what code is being executed and generates a
|
|
149
|
-
report about it.
|
|
150
|
-
|
|
151
|
-
### Notes on specific frameworks and test utilities
|
|
152
|
-
|
|
153
|
-
For some frameworks and testing tools there are quirks and problems you might want to know about if you want
|
|
154
|
-
to use SimpleCov with them. Here's an overview of the known ones:
|
|
155
|
-
|
|
156
|
-
<table>
|
|
157
|
-
<tr><th>Framework</th><th>Notes</th><th>Issue</th></tr>
|
|
158
|
-
<tr>
|
|
159
|
-
<th>
|
|
160
|
-
parallel_tests
|
|
161
|
-
</th>
|
|
162
|
-
<td>
|
|
163
|
-
As of 0.8.0, SimpleCov should correctly recognize parallel_tests and
|
|
164
|
-
supplement your test suite names with their corresponding test env
|
|
165
|
-
numbers. SimpleCov locks the resultset cache while merging, ensuring no
|
|
166
|
-
race conditions occur when results are merged.
|
|
167
|
-
</td>
|
|
168
|
-
<td>
|
|
169
|
-
<a href="https://github.com/simplecov-ruby/simplecov/issues/64">#64</a> &
|
|
170
|
-
<a href="https://github.com/simplecov-ruby/simplecov/pull/185">#185</a>
|
|
171
|
-
</td>
|
|
172
|
-
</tr>
|
|
173
|
-
<tr>
|
|
174
|
-
<th>
|
|
175
|
-
knapsack_pro
|
|
176
|
-
</th>
|
|
177
|
-
<td>
|
|
178
|
-
To make SimpleCov work with Knapsack Pro Queue Mode to split tests in parallel on CI jobs you need to provide CI node index number to the <code>SimpleCov.command_name</code> in <code>KnapsackPro::Hooks::Queue.before_queue</code> hook.
|
|
179
|
-
</td>
|
|
180
|
-
<td>
|
|
181
|
-
<a href="https://knapsackpro.com/faq/question/how-to-use-simplecov-in-queue-mode">Tip</a>
|
|
182
|
-
</td>
|
|
183
|
-
</tr>
|
|
184
|
-
<tr>
|
|
185
|
-
<th>
|
|
186
|
-
RubyMine
|
|
187
|
-
</th>
|
|
188
|
-
<td>
|
|
189
|
-
The <a href="https://www.jetbrains.com/ruby/">RubyMine IDE</a> has
|
|
190
|
-
built-in support for SimpleCov's coverage reports, though you might need
|
|
191
|
-
to explicitly set the output root using `SimpleCov.root('foo/bar/baz')`
|
|
192
|
-
</td>
|
|
193
|
-
<td>
|
|
194
|
-
<a href="https://github.com/simplecov-ruby/simplecov/issues/95">#95</a>
|
|
195
|
-
</td>
|
|
196
|
-
</tr>
|
|
197
|
-
<tr>
|
|
198
|
-
<th>
|
|
199
|
-
Spork
|
|
200
|
-
</th>
|
|
201
|
-
<td>
|
|
202
|
-
Because of how Spork works internally (using preforking), there used to
|
|
203
|
-
be trouble when using SimpleCov with it, but that has apparently been
|
|
204
|
-
resolved with a specific configuration strategy. See <a
|
|
205
|
-
href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">this</a>
|
|
206
|
-
comment.
|
|
207
|
-
</td>
|
|
208
|
-
<td>
|
|
209
|
-
<a href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">#42</a>
|
|
210
|
-
</td>
|
|
211
|
-
</tr>
|
|
212
|
-
<tr>
|
|
213
|
-
<th>
|
|
214
|
-
Spring
|
|
215
|
-
</th>
|
|
216
|
-
<td>
|
|
217
|
-
<a href="#want-to-use-spring-with-simplecov">See section below.</a>
|
|
218
|
-
</td>
|
|
219
|
-
<td>
|
|
220
|
-
<a href="https://github.com/simplecov-ruby/simplecov/issues/381">#381</a>
|
|
221
|
-
</td>
|
|
222
|
-
</tr>
|
|
223
|
-
<tr>
|
|
224
|
-
<th>
|
|
225
|
-
Test/Unit
|
|
226
|
-
</th>
|
|
227
|
-
<td>
|
|
228
|
-
Test Unit 2 used to mess with ARGV, leading to a failure to detect the
|
|
229
|
-
test process name in SimpleCov. <code>test-unit</code> releases 2.4.3+
|
|
230
|
-
(Dec 11th, 2011) should have this problem resolved.
|
|
231
|
-
</td>
|
|
232
|
-
<td>
|
|
233
|
-
<a href="https://github.com/simplecov-ruby/simplecov/issues/45">#45</a> &
|
|
234
|
-
<a href="https://github.com/test-unit/test-unit/pull/12">test-unit/test-unit#12</a>
|
|
235
|
-
</td>
|
|
236
|
-
</tr>
|
|
237
|
-
</table>
|
|
238
|
-
|
|
239
|
-
## Configuring SimpleCov
|
|
240
|
-
|
|
241
|
-
[Configuration] settings can be applied in three formats, which are completely equivalent:
|
|
242
|
-
|
|
243
|
-
* The most common way is to configure it directly in your start block:
|
|
244
|
-
|
|
245
|
-
```ruby
|
|
246
|
-
SimpleCov.start do
|
|
247
|
-
some_config_option 'foo'
|
|
248
|
-
end
|
|
74
|
+
```sh
|
|
75
|
+
simplecov open
|
|
249
76
|
```
|
|
250
|
-
* You can also set all configuration options directly:
|
|
251
77
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
concise way, use:
|
|
78
|
+
(The bundled `simplecov` CLI picks the right opener for your platform:
|
|
79
|
+
`open` on macOS, `xdg-open` on Linux/BSD, `start` on Windows. Pass
|
|
80
|
+
`--report PATH` to open a non-default location. See the
|
|
81
|
+
[command-line interface](docs/CLI.md) for the full set of subcommands.)
|
|
257
82
|
|
|
258
|
-
|
|
259
|
-
SimpleCov.configure do
|
|
260
|
-
some_config_option 'foo'
|
|
261
|
-
end
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Please check out the [Configuration] API documentation to find out what you can customize.
|
|
83
|
+
5. Optionally, keep coverage results out of Git:
|
|
265
84
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
normally have to set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
|
|
85
|
+
```sh
|
|
86
|
+
echo coverage >> .gitignore
|
|
87
|
+
```
|
|
270
88
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
89
|
+
For Rails applications, SimpleCov ships a built-in `rails`
|
|
90
|
+
[profile](docs/Configuration.md#profiles) that sets up groups for your
|
|
91
|
+
Controllers, Models, Helpers, and Libraries:
|
|
274
92
|
|
|
275
93
|
```ruby
|
|
276
|
-
# test/test_helper.rb
|
|
277
94
|
require 'simplecov'
|
|
278
|
-
|
|
279
|
-
# features/support/env.rb
|
|
280
|
-
require 'simplecov'
|
|
281
|
-
|
|
282
|
-
# .simplecov
|
|
283
|
-
SimpleCov.start 'rails' do
|
|
284
|
-
# any custom configs like groups and filters can be here at a central place
|
|
285
|
-
end
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
Using `.simplecov` rather than separately requiring SimpleCov multiple times is recommended if you are merging multiple
|
|
289
|
-
test frameworks like Cucumber and RSpec that rely on each other, as invoking SimpleCov multiple times can cause coverage
|
|
290
|
-
information to be lost.
|
|
291
|
-
|
|
292
|
-
## Branch coverage (ruby "~> 2.5")
|
|
293
|
-
Add branch coverage measurement statistics to your results. Supported in CRuby versions 2.5+.
|
|
294
|
-
|
|
295
|
-
```ruby
|
|
296
|
-
SimpleCov.start do
|
|
297
|
-
enable_coverage :branch
|
|
298
|
-
end
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Branch coverage is a feature introduced in Ruby 2.5 concerning itself with whether a
|
|
302
|
-
particular branch of a condition had been executed. Line coverage on the other hand
|
|
303
|
-
is only interested in whether a line of code has been executed.
|
|
304
|
-
|
|
305
|
-
This comes in handy for instance for one line conditionals:
|
|
306
|
-
|
|
307
|
-
```ruby
|
|
308
|
-
number.odd? ? "odd" : "even"
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
In line coverage this line would always be marked as executed but you'd never know if both
|
|
312
|
-
conditions were met. Guard clauses have a similar story:
|
|
313
|
-
|
|
314
|
-
```ruby
|
|
315
|
-
return if number.odd?
|
|
316
|
-
|
|
317
|
-
# more code
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
If all the code in that method was covered you'd never know if the guard clause was ever
|
|
321
|
-
triggered! With line coverage as just evaluating the condition marks it as covered.
|
|
322
|
-
|
|
323
|
-
In the HTML report the lines of code will be annotated like `branch_type: hit_count`:
|
|
324
|
-
|
|
325
|
-
* `then: 2` - the then branch (of an `if`) was executed twice
|
|
326
|
-
* `else: 0` - the else branch (of an `if` or `case`) was never executed
|
|
327
|
-
|
|
328
|
-
Not that even if you don't declare an `else` branch it will still show up in the coverage
|
|
329
|
-
reports meaning that the condition of the `if` was not hit or that no `when` of `case`
|
|
330
|
-
was hit during the test runs.
|
|
331
|
-
|
|
332
|
-
**Is branch coverage strictly better?** No. Branch coverage really only concerns itself with
|
|
333
|
-
conditionals - meaning coverage of sequential code is of no interest to it. A file without
|
|
334
|
-
conditional logic will have no branch coverage data and SimpleCov will report 0 of 0
|
|
335
|
-
branches covered as 100% (as everything that can be covered was covered).
|
|
336
|
-
|
|
337
|
-
Hence, we recommend looking at both metrics together. Branch coverage might also be a good
|
|
338
|
-
overall metric to look at - while you might be missing only 10% of your lines that might
|
|
339
|
-
account for 50% of your branches for instance.
|
|
340
|
-
|
|
341
|
-
## Primary Coverage
|
|
342
|
-
|
|
343
|
-
By default, the primary coverage type is `line`. To set the primary coverage to something else, use the following:
|
|
344
|
-
|
|
345
|
-
```ruby
|
|
346
|
-
# or in configure SimpleCov.primary_coverage :branch
|
|
347
|
-
SimpleCov.start do
|
|
348
|
-
enable_coverage :branch
|
|
349
|
-
primary_coverage :branch
|
|
350
|
-
end
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
Primary coverage determines what will come in first all output, and the type of coverage to check if you don't specify the type of coverage when customizing exit behavior (`SimpleCov.minimum_coverage 90`).
|
|
354
|
-
|
|
355
|
-
Note that coverage must first be enabled for non-default coverage types.
|
|
356
|
-
|
|
357
|
-
## Coverage for eval
|
|
358
|
-
|
|
359
|
-
You can measure coverage for code that is evaluated by `Kernel#eval`. Supported in CRuby versions 3.2+.
|
|
360
|
-
|
|
361
|
-
```ruby
|
|
362
|
-
SimpleCov.start do
|
|
363
|
-
enable_coverage_for_eval
|
|
364
|
-
end
|
|
95
|
+
SimpleCov.start 'rails'
|
|
365
96
|
```
|
|
366
97
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
## Filters
|
|
370
|
-
|
|
371
|
-
Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
|
|
372
|
-
files OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source
|
|
373
|
-
files in the gems you are using.
|
|
374
|
-
|
|
375
|
-
You can define your own to remove things like configuration files, tests or whatever you don't need in your coverage
|
|
376
|
-
report.
|
|
98
|
+
## Example output
|
|
377
99
|
|
|
378
|
-
|
|
100
|
+
#### Coverage results report
|
|
379
101
|
|
|
380
|
-
|
|
381
|
-
file's path), a block or by passing in your own Filter class.
|
|
102
|
+

|
|
382
103
|
|
|
383
|
-
####
|
|
104
|
+
#### Source file coverage details view
|
|
384
105
|
|
|
385
|
-
|
|
386
|
-
SimpleCov.start do
|
|
387
|
-
add_filter "/test/"
|
|
388
|
-
end
|
|
389
|
-
```
|
|
106
|
+

|
|
390
107
|
|
|
391
|
-
|
|
108
|
+
## Configuration at a glance
|
|
392
109
|
|
|
393
|
-
|
|
110
|
+
Configuration goes in your start block, or in a `.simplecov` file at the
|
|
111
|
+
project root when several test suites share it. The API is built around a
|
|
112
|
+
small set of consistent verbs: formatters are picked by name, thresholds
|
|
113
|
+
live in a per-criterion `coverage` block where scope is a uniform `per:`
|
|
114
|
+
argument, and misses can be capped as absolute counts rather than ratios:
|
|
394
115
|
|
|
395
116
|
```ruby
|
|
396
117
|
SimpleCov.start do
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
SimpleCov.start do
|
|
407
|
-
add_filter do |source_file|
|
|
408
|
-
source_file.lines.count < 5
|
|
118
|
+
enable_coverage :branch # track branches as well as lines
|
|
119
|
+
cover "{app,lib}/**/*.rb" # report on these files, even if never loaded
|
|
120
|
+
skip "app/legacy" # ...but leave these out
|
|
121
|
+
group "Models", "app/models" # organize the report into groups
|
|
122
|
+
|
|
123
|
+
coverage :line do
|
|
124
|
+
minimum 90 # fail the suite below 90% line coverage
|
|
125
|
+
maximum_drop 1 # ...or when coverage drops more than 1%
|
|
126
|
+
maximum_missed 5, per: :file # no file may carry more than 5 uncovered lines
|
|
409
127
|
end
|
|
410
|
-
end
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be
|
|
414
|
-
removed from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to
|
|
415
|
-
learn about the methods available to you. In the above example, the filter will remove all files that have less than 5
|
|
416
|
-
lines of code.
|
|
417
|
-
|
|
418
|
-
#### Custom filter class
|
|
419
128
|
|
|
420
|
-
|
|
421
|
-
class LineFilter < SimpleCov::Filter
|
|
422
|
-
def matches?(source_file)
|
|
423
|
-
source_file.lines.count < filter_argument
|
|
424
|
-
end
|
|
129
|
+
coverage :branch, minimum: 80, ignore: :implicit_else
|
|
425
130
|
end
|
|
426
|
-
|
|
427
|
-
SimpleCov.add_filter LineFilter.new(5)
|
|
428
131
|
```
|
|
429
132
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
133
|
+
Everything you're using today keeps working. Legacy spellings warn and name
|
|
134
|
+
their replacement, and once you've migrated, `deprecations :raise` turns any
|
|
135
|
+
old spelling that creeps back in into an error. The
|
|
136
|
+
[migration map](docs/Configuration.md#migrating-from-the-legacy-configuration-api)
|
|
137
|
+
has the full before and after, and every option is documented in
|
|
138
|
+
[docs/Configuration.md](docs/Configuration.md), including criteria, filters,
|
|
139
|
+
groups, profiles, and thresholds.
|
|
434
140
|
|
|
435
|
-
|
|
141
|
+
## Tracking which test covers each line
|
|
436
142
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
proc = Proc.new { |source_file| false }
|
|
440
|
-
add_filter ["string", /regex/, proc, LineFilter.new(5)]
|
|
441
|
-
end
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
You can pass in an array containing any of the other filter types.
|
|
445
|
-
|
|
446
|
-
#### Ignoring/skipping code
|
|
447
|
-
|
|
448
|
-
You can exclude code from the coverage report by wrapping it in `# :nocov:`.
|
|
449
|
-
|
|
450
|
-
```ruby
|
|
451
|
-
# :nocov:
|
|
452
|
-
def skip_this_method
|
|
453
|
-
never_reached
|
|
454
|
-
end
|
|
455
|
-
# :nocov:
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/simplecov-ruby/simplecov/blob/main/features/config_nocov_token.feature)
|
|
459
|
-
|
|
460
|
-
**Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If
|
|
461
|
-
you appropriately test the public interface of your classes and objects you should automatically get full coverage of
|
|
462
|
-
your private methods.
|
|
463
|
-
|
|
464
|
-
## Default root filter and coverage for things outside of it
|
|
465
|
-
|
|
466
|
-
By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want
|
|
467
|
-
to include coverage reports for things you include as a gem, for example a Rails Engine.
|
|
468
|
-
|
|
469
|
-
Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/simplecov-ruby/simplecov/issues/221)
|
|
470
|
-
that shows how you can achieve just that:
|
|
471
|
-
|
|
472
|
-
```ruby
|
|
473
|
-
SimpleCov.start :rails do
|
|
474
|
-
filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults
|
|
475
|
-
add_filter do |src|
|
|
476
|
-
!(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /my_engine/
|
|
477
|
-
end
|
|
478
|
-
end
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
## Groups
|
|
482
|
-
|
|
483
|
-
You can separate your source files into groups. For example, in a Rails app, you'll want to have separate listings for
|
|
484
|
-
Models, Controllers, Helpers, and Libs. Group definition works similarly to Filters (and also accepts custom
|
|
485
|
-
filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering
|
|
486
|
-
results, which exclude files from results when the filter results in a true value.
|
|
487
|
-
|
|
488
|
-
Add your groups with:
|
|
143
|
+
Coverage normally tells you whether a line ran, not what ran it. `track_tests`
|
|
144
|
+
records the other half of the story:
|
|
489
145
|
|
|
490
146
|
```ruby
|
|
491
147
|
SimpleCov.start do
|
|
492
|
-
|
|
493
|
-
add_group "Controllers", "app/controllers"
|
|
494
|
-
add_group "Long files" do |src_file|
|
|
495
|
-
src_file.lines.count > 100
|
|
496
|
-
end
|
|
497
|
-
add_group "Multiple Files", ["app/models", "app/controllers"] # You can also pass in an array
|
|
498
|
-
add_group "Short files", LineFilter.new(5) # Using the LineFilter class defined in Filters section above
|
|
499
|
-
end
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
## Merging results
|
|
503
|
-
|
|
504
|
-
You normally want to have your coverage analyzed across ALL of your test suites, right?
|
|
505
|
-
|
|
506
|
-
Simplecov automatically caches coverage results in your
|
|
507
|
-
(coverage_path)/.resultset.json, and will merge or override those with
|
|
508
|
-
subsequent runs, depending on whether simplecov considers those subsequent runs
|
|
509
|
-
as different test suites or as the same test suite as the cached results. To
|
|
510
|
-
make this distinction, simplecov has the concept of "test suite names".
|
|
511
|
-
|
|
512
|
-
### Test suite names
|
|
513
|
-
|
|
514
|
-
SimpleCov tries to guess the name of the currently running test suite based upon the shell command the tests
|
|
515
|
-
are running on. This should work fine for Unit Tests, RSpec, and Cucumber. If it fails, it will use the shell
|
|
516
|
-
command that invoked the test suite as a command name.
|
|
517
|
-
|
|
518
|
-
If you have some non-standard setup and still want nicely labeled test suites, you have to give Simplecov a
|
|
519
|
-
cue as to what the name of the currently running test suite is. You can do so by specifying
|
|
520
|
-
`SimpleCov.command_name` in one test file that is part of your specific suite.
|
|
521
|
-
|
|
522
|
-
To customize the suite names on a Rails app (yeah, sorry for being Rails-biased, but everyone knows what
|
|
523
|
-
the structure of those projects is. You can apply this accordingly to the RSpecs in your
|
|
524
|
-
Outlook-WebDAV-Calendar-Sync gem), you could do something like this:
|
|
525
|
-
|
|
526
|
-
```ruby
|
|
527
|
-
# test/unit/some_test.rb
|
|
528
|
-
SimpleCov.command_name 'test:units'
|
|
529
|
-
|
|
530
|
-
# test/functionals/some_controller_test.rb
|
|
531
|
-
SimpleCov.command_name "test:functionals"
|
|
532
|
-
|
|
533
|
-
# test/integration/some_integration_test.rb
|
|
534
|
-
SimpleCov.command_name "test:integration"
|
|
535
|
-
|
|
536
|
-
# features/support/env.rb
|
|
537
|
-
SimpleCov.command_name "features"
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
Note that this only has to be invoked ONCE PER TEST SUITE, so even if you have 200 unit test files,
|
|
541
|
-
specifying it in `some_test.rb` is enough.
|
|
542
|
-
|
|
543
|
-
Last but not least **if multiple suites resolve to the same `command_name`** be aware that the coverage results **will
|
|
544
|
-
clobber each other instead of being merged**. SimpleCov is smart enough to detect unique names for the most common
|
|
545
|
-
setups, but if you have more than one test suite that doesn't follow a common pattern then you will want to manually
|
|
546
|
-
ensure that each suite gets a unique `command_name`.
|
|
547
|
-
|
|
548
|
-
If you are running tests in parallel each process has the potential to clobber results from the other test processes.
|
|
549
|
-
If you are relying on the default `command_name` then SimpleCov will attempt to detect and avoid parallel test suite
|
|
550
|
-
`command_name` collisions based on the presence of `ENV['PARALLEL_TEST_GROUPS']` and `ENV['TEST_ENV_NUMBER']`. If your
|
|
551
|
-
parallel test runner does not set one or both of these then *you must* set a `command_name` and ensure that it is unique
|
|
552
|
-
per process (eg. `command_name "Unit Tests PID #{$$}"`).
|
|
553
|
-
|
|
554
|
-
If you are using parallel_tests, you must incorporate `TEST_ENV_NUMBER` into the command name yourself, in
|
|
555
|
-
order for SimpleCov to merge the results correctly. For example:
|
|
556
|
-
|
|
557
|
-
```ruby
|
|
558
|
-
# spec/spec_helper.rb
|
|
559
|
-
SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '')
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
[simplecov-html] prints the used test suites in the footer of the generated coverage report.
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
### Merging test runs under the same execution environment
|
|
566
|
-
|
|
567
|
-
Test results are automatically merged with previous runs in the same execution
|
|
568
|
-
environment when generating the result, so when coverage is set up properly for
|
|
569
|
-
Cucumber and your unit / functional / integration tests, all of those test
|
|
570
|
-
suites will be taken into account when building the coverage report.
|
|
571
|
-
|
|
572
|
-
#### Timeout for merge
|
|
573
|
-
|
|
574
|
-
Of course, your cached coverage data is likely to become invalid at some point. Thus, when automatically merging
|
|
575
|
-
subsequent test runs, result sets that are older than `SimpleCov.merge_timeout` will not be used any more. By default,
|
|
576
|
-
the timeout is 600 seconds (10 minutes), and you can raise (or lower) it by specifying `SimpleCov.merge_timeout 3600`
|
|
577
|
-
(1 hour), or, inside a configure/start block, with just `merge_timeout 3600`.
|
|
578
|
-
|
|
579
|
-
You can deactivate this automatic merging altogether with `SimpleCov.use_merging false`.
|
|
580
|
-
|
|
581
|
-
### Merging test runs under different execution environments
|
|
582
|
-
|
|
583
|
-
If your tests are done in parallel across multiple build machines, you can fetch them all and merge them into a single
|
|
584
|
-
result set using the `SimpleCov.collate` method. This can be added to a Rakefile or script file, having downloaded a set of
|
|
585
|
-
`.resultset.json` files from each parallel test run.
|
|
586
|
-
|
|
587
|
-
```ruby
|
|
588
|
-
# lib/tasks/coverage_report.rake
|
|
589
|
-
namespace :coverage do
|
|
590
|
-
desc "Collates all result sets generated by the different test runners"
|
|
591
|
-
task :report do
|
|
592
|
-
require 'simplecov'
|
|
593
|
-
|
|
594
|
-
SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"]
|
|
595
|
-
end
|
|
148
|
+
track_tests
|
|
596
149
|
end
|
|
597
150
|
```
|
|
598
151
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
complex formatters in the final `SimpleCov.collate` run.
|
|
605
|
-
|
|
606
|
-
```ruby
|
|
607
|
-
# spec/spec_helper.rb
|
|
608
|
-
require 'simplecov'
|
|
609
|
-
|
|
610
|
-
SimpleCov.start 'rails' do
|
|
611
|
-
# Disambiguates individual test runs
|
|
612
|
-
command_name "Job #{ENV["TEST_ENV_NUMBER"]}" if ENV["TEST_ENV_NUMBER"]
|
|
613
|
-
|
|
614
|
-
if ENV['CI']
|
|
615
|
-
formatter SimpleCov::Formatter::SimpleFormatter
|
|
616
|
-
else
|
|
617
|
-
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
618
|
-
SimpleCov::Formatter::SimpleFormatter,
|
|
619
|
-
SimpleCov::Formatter::HTMLFormatter
|
|
620
|
-
])
|
|
621
|
-
end
|
|
152
|
+
RSpec examples and Minitest tests are wrapped automatically. In the HTML
|
|
153
|
+
report, covered lines that no test executed (they only ran at load time, or in
|
|
154
|
+
suite setup) drain to a distinct tint, so coverage that merely *loads* code
|
|
155
|
+
stops passing for coverage that *tests* it, and clicking a line's badge lists
|
|
156
|
+
the tests that cover it. The same recording answers from the terminal:
|
|
622
157
|
|
|
623
|
-
|
|
624
|
-
|
|
158
|
+
```sh
|
|
159
|
+
$ simplecov tests lib/simplecov/result.rb:42
|
|
160
|
+
spec/result_spec.rb:42
|
|
625
161
|
```
|
|
626
162
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
163
|
+
The output is one test id per line and nothing else, so it pipes straight into
|
|
164
|
+
a runner. `simplecov tests --redundant` inverts the question, listing the
|
|
165
|
+
tests whose covered lines other tests also cover, which is where a
|
|
166
|
+
[test-pruning session](docs/Redundant_Tests.md) starts. Recording has a real
|
|
167
|
+
cost, which is why it's opt-in and comes with levers to control it. See
|
|
168
|
+
[the configuration docs](docs/Configuration.md#tracking-which-test-covers-each-line).
|
|
632
169
|
|
|
633
|
-
|
|
634
|
-
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
635
|
-
SimpleCov::Formatter::SimpleFormatter,
|
|
636
|
-
SimpleCov::Formatter::HTMLFormatter
|
|
637
|
-
])
|
|
638
|
-
end
|
|
639
|
-
end
|
|
640
|
-
end
|
|
641
|
-
```
|
|
170
|
+
## Finding dead code in production
|
|
642
171
|
|
|
643
|
-
|
|
172
|
+
SimpleCov can also measure production code usage, the surest way to find
|
|
173
|
+
dead code. The old trick was to plant a log line in a suspect method and
|
|
174
|
+
watch production for a while. Oneshot coverage runs that experiment for
|
|
175
|
+
every line at once: a line reports its first execution and nothing after,
|
|
176
|
+
so a live process records what real traffic uses with the least possible
|
|
177
|
+
impact on performance. `simplecov dead-code` then crosses the recording
|
|
178
|
+
with the test report and turns it into insight you can act on. Code
|
|
179
|
+
neither tests nor traffic touch is safe to delete, and code production
|
|
180
|
+
runs but tests skip is the most valuable test you haven't written. The
|
|
181
|
+
HTML report and `coverage.json` include the same production data. See
|
|
182
|
+
[docs/Production.md](docs/Production.md) for more details on why and how
|
|
183
|
+
to set it up.
|
|
644
184
|
|
|
645
|
-
|
|
646
|
-
This modifies ruby's core Process.fork method so that SimpleCov can see into it, appending `" (subprocess #{pid})"`
|
|
647
|
-
to the `SimpleCov.command_name`, with results that can be merged together using SimpleCov's merging feature.
|
|
185
|
+
## Coverage of just your change
|
|
648
186
|
|
|
649
|
-
|
|
187
|
+
An overall number moves slowly on a mature codebase, but "is the code in this
|
|
188
|
+
change tested?" has a crisp answer the day you ask it. `simplecov patch` reads
|
|
189
|
+
the git diff against a base ref and scores only the lines you touched:
|
|
650
190
|
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
# be quiet, the parent process will be in charge of output and checking coverage totals
|
|
657
|
-
SimpleCov.print_error_status = false
|
|
658
|
-
SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
|
659
|
-
SimpleCov.minimum_coverage 0
|
|
660
|
-
# start
|
|
661
|
-
SimpleCov.start
|
|
662
|
-
end
|
|
191
|
+
```sh
|
|
192
|
+
$ simplecov patch --base main --minimum 100
|
|
193
|
+
88.00% (22/25) lines lib/simplecov/cli/patch.rb missing 41-43
|
|
194
|
+
100.00% (4/4) lines lib/simplecov/result.rb
|
|
195
|
+
Patch coverage: 89.66% (26/29) lines
|
|
663
196
|
```
|
|
664
197
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
198
|
+
`--minimum` turns it into a gate, so a project that can't lift its overall
|
|
199
|
+
number in one pull request can still require that everything it adds is
|
|
200
|
+
covered. The flip side is `simplecov affected`, which uses a `track_tests`
|
|
201
|
+
recording to select the tests that touch your changed code and hand them to
|
|
202
|
+
the runner, falling back (loudly) to the full suite whenever the map can't be
|
|
203
|
+
trusted:
|
|
668
204
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
Add a .simplecov_spawn.rb file to your project root
|
|
673
|
-
```ruby
|
|
674
|
-
# .simplecov_spawn.rb
|
|
675
|
-
require 'simplecov' # this will also pick up whatever config is in .simplecov
|
|
676
|
-
# so ensure it just contains configuration, and doesn't call SimpleCov.start.
|
|
677
|
-
SimpleCov.command_name 'spawn' # As this is not for a test runner directly, script doesn't have a pre-defined base command_name
|
|
678
|
-
SimpleCov.at_fork.call(Process.pid) # Use the per-process setup described previously
|
|
679
|
-
SimpleCov.start # only now can we start.
|
|
205
|
+
```sh
|
|
206
|
+
$ simplecov affected --base main --run bundle exec rspec
|
|
680
207
|
```
|
|
681
|
-
Then, instead of calling your script directly, like:
|
|
682
|
-
```ruby
|
|
683
|
-
PTY.spawn('my_script.rb') do # ...
|
|
684
|
-
```
|
|
685
|
-
Use bin/ruby to require the new .simplecov_spawn file, then your script
|
|
686
|
-
```ruby
|
|
687
|
-
PTY.spawn('ruby -r./.simplecov_spawn my_script.rb') do # ...
|
|
688
|
-
```
|
|
689
|
-
|
|
690
|
-
## Running coverage only on demand
|
|
691
208
|
|
|
692
|
-
|
|
693
|
-
drop was only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you
|
|
694
|
-
run your tests because it doesn't do your test speed any harm and you're always equipped with the latest and greatest
|
|
695
|
-
coverage results.
|
|
209
|
+
Both commands are documented in [the CLI docs](docs/CLI.md).
|
|
696
210
|
|
|
697
|
-
|
|
211
|
+
## Covering views
|
|
698
212
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
```ruby
|
|
703
|
-
SimpleCov.start if ENV["COVERAGE"]
|
|
704
|
-
```
|
|
705
|
-
|
|
706
|
-
Then, SimpleCov will only run if you execute your tests like this:
|
|
707
|
-
|
|
708
|
-
```shell
|
|
709
|
-
COVERAGE=true rake test
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
## Errors and exit statuses
|
|
713
|
-
|
|
714
|
-
To aid in debugging issues, if an error is raised, SimpleCov will print a message to `STDERR`
|
|
715
|
-
with the exit status of the error, like:
|
|
716
|
-
|
|
717
|
-
```
|
|
718
|
-
SimpleCov failed with exit 1
|
|
719
|
-
```
|
|
720
|
-
|
|
721
|
-
This `STDERR` message can be disabled with:
|
|
722
|
-
|
|
723
|
-
```
|
|
724
|
-
SimpleCov.print_error_status = false
|
|
725
|
-
```
|
|
726
|
-
|
|
727
|
-
## Profiles
|
|
728
|
-
|
|
729
|
-
By default, SimpleCov's only config assumption is that you only want coverage reports for files inside your project
|
|
730
|
-
root. To save yourself from repetitive configuration, you can use predefined blocks of configuration, called 'profiles',
|
|
731
|
-
or define your own.
|
|
732
|
-
|
|
733
|
-
You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov
|
|
734
|
-
comes bundled with a 'rails' profile. It looks somewhat like this:
|
|
735
|
-
|
|
736
|
-
```ruby
|
|
737
|
-
SimpleCov.profiles.define 'rails' do
|
|
738
|
-
add_filter '/test/'
|
|
739
|
-
add_filter '/config/'
|
|
740
|
-
|
|
741
|
-
add_group 'Controllers', 'app/controllers'
|
|
742
|
-
add_group 'Models', 'app/models'
|
|
743
|
-
add_group 'Helpers', 'app/helpers'
|
|
744
|
-
add_group 'Libraries', 'lib'
|
|
745
|
-
end
|
|
746
|
-
```
|
|
747
|
-
|
|
748
|
-
As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch SimpleCov with:
|
|
749
|
-
|
|
750
|
-
```ruby
|
|
751
|
-
SimpleCov.start 'rails'
|
|
752
|
-
```
|
|
753
|
-
|
|
754
|
-
or
|
|
213
|
+
View templates execute real logic, and now they can be part of the report.
|
|
214
|
+
`cover_views` brings ERB, Haml, and Slim templates in, measured through eval
|
|
215
|
+
coverage:
|
|
755
216
|
|
|
756
217
|
```ruby
|
|
757
218
|
SimpleCov.start 'rails' do
|
|
758
|
-
|
|
759
|
-
end
|
|
760
|
-
```
|
|
761
|
-
|
|
762
|
-
### Custom profiles
|
|
763
|
-
|
|
764
|
-
You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an
|
|
765
|
-
existing profile and customize it so you can reuse it in unit tests and Cucumber features. For example:
|
|
766
|
-
|
|
767
|
-
```ruby
|
|
768
|
-
# lib/simplecov_custom_profile.rb
|
|
769
|
-
require 'simplecov'
|
|
770
|
-
SimpleCov.profiles.define 'myprofile' do
|
|
771
|
-
load_profile 'rails'
|
|
772
|
-
add_filter 'vendor' # Don't include vendored stuff
|
|
773
|
-
end
|
|
774
|
-
|
|
775
|
-
# features/support/env.rb
|
|
776
|
-
require 'simplecov_custom_profile'
|
|
777
|
-
SimpleCov.start 'myprofile'
|
|
778
|
-
|
|
779
|
-
# test/test_helper.rb
|
|
780
|
-
require 'simplecov_custom_profile'
|
|
781
|
-
SimpleCov.start 'myprofile'
|
|
782
|
-
```
|
|
783
|
-
|
|
784
|
-
## Customizing exit behaviour
|
|
785
|
-
|
|
786
|
-
You can define what SimpleCov should do when your test suite finishes by customizing the at_exit hook:
|
|
787
|
-
|
|
788
|
-
```ruby
|
|
789
|
-
SimpleCov.at_exit do
|
|
790
|
-
SimpleCov.result.format!
|
|
219
|
+
cover_views
|
|
791
220
|
end
|
|
792
221
|
```
|
|
793
222
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
```ruby
|
|
801
|
-
SimpleCov.minimum_coverage 90
|
|
802
|
-
# same as above (the default is to check line coverage)
|
|
803
|
-
SimpleCov.minimum_coverage line: 90
|
|
804
|
-
# check for a minimum line coverage of 90% and minimum 80% branch coverage
|
|
805
|
-
SimpleCov.minimum_coverage line: 90, branch: 80
|
|
806
|
-
```
|
|
807
|
-
|
|
808
|
-
### Minimum coverage by file
|
|
809
|
-
|
|
810
|
-
You can define the minimum coverage by file percentage expected. SimpleCov will return non-zero if unmet. This is useful
|
|
811
|
-
to help ensure coverage is relatively consistent, rather than being skewed by particularly good or bad areas of the code.
|
|
223
|
+
Templates are ordinary files in the report, highlighted in their own language
|
|
224
|
+
and grouped under Views by the `rails` profile, and a template no test renders
|
|
225
|
+
shows up at 0% instead of being quietly missing. Expect your overall number to
|
|
226
|
+
drop the first time you turn this on. That's the point. See
|
|
227
|
+
[view coverage](docs/Configuration.md#view-coverage).
|
|
812
228
|
|
|
813
|
-
|
|
814
|
-
SimpleCov.minimum_coverage_by_file 80
|
|
815
|
-
# same as above (the default is to check line coverage by file)
|
|
816
|
-
SimpleCov.minimum_coverage_by_file line: 80
|
|
817
|
-
# check for a minimum line coverage by file of 90% and minimum 80% branch coverage
|
|
818
|
-
SimpleCov.minimum_coverage_by_file line: 90, branch: 80
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
### Maximum coverage drop
|
|
229
|
+
## Per-file ratchets and coverage history
|
|
822
230
|
|
|
823
|
-
|
|
231
|
+
On a legacy codebase, one per-file minimum does nothing useful: set it to what
|
|
232
|
+
the worst file scores and every other file is allowed to sink to that level.
|
|
233
|
+
`simplecov ratchet` writes a checked-in baseline instead, giving each file its
|
|
234
|
+
own floor at the coverage it has already reached:
|
|
824
235
|
|
|
825
|
-
```
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
SimpleCov.maximum_coverage_drop line: 5
|
|
829
|
-
# check for a maximum line drop of 5% and maximum 10% branch drop
|
|
830
|
-
SimpleCov.maximum_coverage_drop line: 5, branch: 10
|
|
236
|
+
```sh
|
|
237
|
+
$ simplecov ratchet
|
|
238
|
+
simplecov ratchet: wrote .simplecov_baseline.yml (3 tightened, 1 pruned, 148 unchanged)
|
|
831
239
|
```
|
|
832
240
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
241
|
+
Floors only ever tighten, so touching a legacy file drags its coverage upward
|
|
242
|
+
and it can never slide back. Think `.rubocop_todo.yml`, applied to coverage.
|
|
243
|
+
To ratchet automatically at the end of every run, add the baseline formatter
|
|
244
|
+
with `formats :html, :baseline`.
|
|
836
245
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
246
|
+
Alongside the floors, every successful run now appends to
|
|
247
|
+
`coverage/.history.json`, so you have a recorded trend rather than just the
|
|
248
|
+
last number. `simplecov history` draws it as sparklines in the terminal, and
|
|
249
|
+
`drop_baseline :median` judges coverage drops against the recorded median
|
|
250
|
+
instead of whatever the previous run happened to score. See
|
|
251
|
+
[the baseline](docs/Configuration.md#per-file-baseline-ratchet) and
|
|
252
|
+
[run history](docs/Configuration.md#run-history) docs.
|
|
844
253
|
|
|
845
|
-
##
|
|
254
|
+
## More from the command line
|
|
846
255
|
|
|
847
|
-
|
|
256
|
+
The `simplecov` CLI has grown from a report opener into a toolbelt. A few
|
|
257
|
+
favorites:
|
|
848
258
|
|
|
849
|
-
```
|
|
850
|
-
|
|
259
|
+
```sh
|
|
260
|
+
$ simplecov watch bundle exec rspec # re-run on save, live-reload the served report
|
|
261
|
+
$ simplecov show lib/foo.rb # annotated source in the terminal
|
|
262
|
+
$ simplecov status # is this report fresh, and for which commit?
|
|
263
|
+
$ simplecov uncovered --missing # worst files, with the exact line ranges to test
|
|
264
|
+
$ simplecov badge --output badge.svg # a shields.io-style SVG, no badge service needed
|
|
851
265
|
```
|
|
852
266
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
As of SimpleCov 0.9, you can specify multiple result formats. Formatters besides the default HTML formatter require separate gems, however.
|
|
860
|
-
|
|
861
|
-
```ruby
|
|
862
|
-
require "simplecov-html"
|
|
863
|
-
|
|
864
|
-
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
|
|
865
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
866
|
-
SimpleCov::Formatter::CSVFormatter,
|
|
867
|
-
])
|
|
868
|
-
```
|
|
869
|
-
|
|
870
|
-
## JSON formatter
|
|
871
|
-
|
|
872
|
-
SimpleCov is packaged with a separate gem called [simplecov_json_formatter](https://github.com/codeclimate-community/simplecov_json_formatter) that provides you with a JSON formatter, this formatter could be useful for different use cases, such as for CI consumption or for reporting to external services.
|
|
873
|
-
|
|
874
|
-
In order to use it you will need to manually load the installed gem like so:
|
|
875
|
-
|
|
876
|
-
```ruby
|
|
877
|
-
require "simplecov_json_formatter"
|
|
878
|
-
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
|
|
879
|
-
```
|
|
880
|
-
|
|
881
|
-
> _Note:_ In case you plan to report your coverage results to CodeClimate services, know that SimpleCov will automatically use the
|
|
882
|
-
> JSON formatter along with the HTML formatter when the `CC_TEST_REPORTER_ID` variable is present in the environment.
|
|
883
|
-
|
|
884
|
-
## Available formatters, editor integrations and hosted services
|
|
885
|
-
|
|
886
|
-
* [Open Source formatter and integration plugins for SimpleCov](doc/alternate-formatters.md)
|
|
887
|
-
* [Editor Integration](doc/editor-integration.md)
|
|
888
|
-
* [Hosted (commercial) services](doc/commercial-services.md)
|
|
889
|
-
|
|
890
|
-
## Ruby version compatibility
|
|
891
|
-
|
|
892
|
-
SimpleCov is built in [Continuous Integration] on Ruby 2.7+ as well as JRuby 9.3+.
|
|
893
|
-
|
|
894
|
-
Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
|
|
895
|
-
|
|
896
|
-
## Want to find dead code in production?
|
|
897
|
-
|
|
898
|
-
Try [Coverband](https://github.com/danmayer/coverband).
|
|
899
|
-
|
|
900
|
-
## Want to use Spring with SimpleCov?
|
|
901
|
-
|
|
902
|
-
If you're using [Spring](https://github.com/rails/spring) to speed up test suite runs and want to run SimpleCov along
|
|
903
|
-
with them, you'll find that it often misreports coverage with the default config due to some sort of eager loading
|
|
904
|
-
issue. Don't despair!
|
|
905
|
-
|
|
906
|
-
One solution is to [explicitly call eager
|
|
907
|
-
load](https://github.com/simplecov-ruby/simplecov/issues/381#issuecomment-347651728)
|
|
908
|
-
in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
|
|
909
|
-
|
|
910
|
-
```ruby
|
|
911
|
-
require 'simplecov'
|
|
912
|
-
SimpleCov.start 'rails'
|
|
913
|
-
Rails.application.eager_load!
|
|
914
|
-
```
|
|
915
|
-
|
|
916
|
-
Alternatively, you could disable Spring while running SimpleCov:
|
|
917
|
-
|
|
918
|
-
```
|
|
919
|
-
DISABLE_SPRING=1 rake test
|
|
920
|
-
```
|
|
921
|
-
|
|
922
|
-
Or you could remove `gem 'spring'` from your `Gemfile`.
|
|
923
|
-
|
|
924
|
-
## Troubleshooting
|
|
925
|
-
|
|
926
|
-
The **most common problem is that simplecov isn't required and started before everything else**. In order to track
|
|
927
|
-
coverage for your whole application **simplecov needs to be the first one** so that it (and the underlying coverage
|
|
928
|
-
library) can subsequently track loaded files and their usage.
|
|
929
|
-
|
|
930
|
-
If you are missing coverage for some code a simple trick is to put a puts statement in there and right after
|
|
931
|
-
`SimpleCov.start` so you can see if the file really was loaded after simplecov was started.
|
|
932
|
-
|
|
933
|
-
```ruby
|
|
934
|
-
# my_code.rb
|
|
935
|
-
class MyCode
|
|
936
|
-
|
|
937
|
-
puts "MyCode is being loaded!"
|
|
938
|
-
|
|
939
|
-
def my_method
|
|
940
|
-
# ...
|
|
941
|
-
end
|
|
942
|
-
end
|
|
943
|
-
|
|
944
|
-
# spec_helper.rb/rails_helper.rb/test_helper.rb/.simplecov whatever
|
|
945
|
-
|
|
946
|
-
SimpleCov.start
|
|
947
|
-
puts "SimpleCov started successfully!"
|
|
948
|
-
```
|
|
949
|
-
|
|
950
|
-
Now when you run your test suite and you see:
|
|
951
|
-
|
|
952
|
-
```
|
|
953
|
-
SimpleCov started successfully!
|
|
954
|
-
MyCode is being loaded!
|
|
955
|
-
```
|
|
956
|
-
|
|
957
|
-
then it's good otherwise you likely have a problem :)
|
|
958
|
-
|
|
959
|
-
## Code of Conduct
|
|
960
|
-
|
|
961
|
-
Everyone participating in this project's development, issue trackers and other channels is expected to follow our
|
|
962
|
-
[Code of Conduct](./CODE_OF_CONDUCT.md)
|
|
963
|
-
|
|
964
|
-
## Contributing
|
|
965
|
-
|
|
966
|
-
See the [contributing guide](https://github.com/simplecov-ruby/simplecov/blob/main/CONTRIBUTING.md).
|
|
967
|
-
|
|
968
|
-
## Kudos
|
|
969
|
-
|
|
970
|
-
Thanks to Aaron Patterson for the original idea for this!
|
|
971
|
-
|
|
972
|
-
## Copyright
|
|
973
|
-
|
|
974
|
-
Copyright (c) 2010-2017 Christoph Olszowka. See MIT-LICENSE for details.
|
|
267
|
+
`watch` deserves the highlight: with a `track_tests` recording in the report,
|
|
268
|
+
a save re-runs only the tests that touch the files you changed, which turns
|
|
269
|
+
the report into something you keep open while writing the test. There is also
|
|
270
|
+
shell tab completion (`simplecov completions fish|bash|zsh`), a man page, and
|
|
271
|
+
a real `--help` on every command. The full tour is in
|
|
272
|
+
[docs/CLI.md](docs/CLI.md).
|