simplecov 0.8.0.pre2 → 0.18.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +368 -27
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +38 -7
- data/ISSUE_TEMPLATE.md +23 -0
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +449 -230
- data/doc/alternate-formatters.md +61 -0
- data/doc/commercial-services.md +20 -0
- data/doc/editor-integration.md +18 -0
- data/lib/simplecov.rb +294 -59
- data/lib/simplecov/combine.rb +30 -0
- data/lib/simplecov/combine/branches_combiner.rb +32 -0
- data/lib/simplecov/combine/files_combiner.rb +25 -0
- data/lib/simplecov/combine/lines_combiner.rb +43 -0
- data/lib/simplecov/combine/results_combiner.rb +60 -0
- data/lib/simplecov/command_guesser.rb +46 -40
- data/lib/simplecov/configuration.rb +346 -221
- data/lib/simplecov/defaults.rb +35 -75
- data/lib/simplecov/exit_codes.rb +9 -4
- data/lib/simplecov/file_list.rb +80 -36
- data/lib/simplecov/filter.rb +51 -3
- data/lib/simplecov/formatter.rb +4 -2
- data/lib/simplecov/formatter/multi_formatter.rb +28 -19
- data/lib/simplecov/formatter/simple_formatter.rb +21 -15
- data/lib/simplecov/last_run.rb +21 -13
- data/lib/simplecov/lines_classifier.rb +48 -0
- data/lib/simplecov/load_global_config.rb +8 -0
- data/lib/simplecov/no_defaults.rb +4 -2
- data/lib/simplecov/profiles.rb +29 -23
- data/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/lib/simplecov/profiles/hidden_filter.rb +5 -0
- data/lib/simplecov/profiles/rails.rb +18 -0
- data/lib/simplecov/profiles/root_filter.rb +10 -0
- data/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/lib/simplecov/result.rb +39 -68
- data/lib/simplecov/result_adapter.rb +30 -0
- data/lib/simplecov/result_merger.rb +110 -60
- data/lib/simplecov/simulate_coverage.rb +29 -0
- data/lib/simplecov/source_file.rb +261 -135
- data/lib/simplecov/source_file/branch.rb +106 -0
- data/lib/simplecov/source_file/line.rb +72 -0
- data/lib/simplecov/useless_results_remover.rb +16 -0
- data/lib/simplecov/version.rb +4 -2
- metadata +48 -197
- data/.gitignore +0 -32
- data/.travis.yml +0 -28
- data/.yardopts +0 -1
- data/Appraisals +0 -8
- data/Gemfile +0 -16
- data/Rakefile +0 -32
- data/cucumber.yml +0 -13
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -45
- data/features/config_coverage_dir.feature +0 -33
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_formatters.feature +0 -52
- data/features/config_merge_timeout.feature +0 -39
- data/features/config_nocov_token.feature +0 -79
- data/features/config_profiles.feature +0 -44
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -121
- data/features/cucumber_basic.feature +0 -29
- data/features/maximum_coverage_drop.feature +0 -36
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/minimum_coverage.feature +0 -59
- data/features/refuse_coverage_drop.feature +0 -35
- data/features/rspec_basic.feature +0 -31
- data/features/rspec_fails_on_initialization.feature +0 -14
- data/features/rspec_groups_and_filters_basic.feature +0 -29
- data/features/rspec_groups_and_filters_complex.feature +0 -35
- data/features/rspec_groups_using_filter_class.feature +0 -40
- data/features/rspec_without_simplecov.feature +0 -20
- data/features/skipping_code_blocks_manually.feature +0 -70
- data/features/step_definitions/html_steps.rb +0 -45
- data/features/step_definitions/simplecov_steps.rb +0 -66
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/env.rb +0 -44
- data/features/test_unit_basic.feature +0 -34
- data/features/test_unit_groups_and_filters_basic.feature +0 -29
- data/features/test_unit_groups_and_filters_complex.feature +0 -35
- data/features/test_unit_groups_using_filter_class.feature +0 -40
- data/features/test_unit_without_simplecov.feature +0 -20
- data/features/unicode_compatiblity.feature +0 -67
- data/gemfiles/multi_json_legacy.gemfile +0 -12
- data/gemfiles/multi_json_new.gemfile +0 -12
- data/lib/simplecov/jruby16_fix.rb +0 -43
- data/lib/simplecov/json.rb +0 -27
- data/lib/simplecov/merge_helpers.rb +0 -39
- data/lib/simplecov/railtie.rb +0 -7
- data/lib/simplecov/railties/tasks.rake +0 -11
- data/simplecov.gemspec +0 -30
- data/test/faked_project/Gemfile +0 -6
- data/test/faked_project/Rakefile +0 -8
- data/test/faked_project/cucumber.yml +0 -13
- data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
- data/test/faked_project/features/support/env.rb +0 -12
- data/test/faked_project/features/test_stuff.feature +0 -6
- data/test/faked_project/lib/faked_project.rb +0 -11
- data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/test/faked_project/lib/faked_project/some_class.rb +0 -29
- data/test/faked_project/spec/faked_spec.rb +0 -11
- data/test/faked_project/spec/meta_magic_spec.rb +0 -10
- data/test/faked_project/spec/some_class_spec.rb +0 -10
- data/test/faked_project/spec/spec_helper.rb +0 -15
- data/test/faked_project/test/faked_test.rb +0 -11
- data/test/faked_project/test/meta_magic_test.rb +0 -13
- data/test/faked_project/test/some_class_test.rb +0 -15
- data/test/faked_project/test/test_helper.rb +0 -16
- data/test/fixtures/app/controllers/sample_controller.rb +0 -10
- data/test/fixtures/app/models/user.rb +0 -10
- data/test/fixtures/deleted_source_sample.rb +0 -15
- data/test/fixtures/frameworks/rspec_bad.rb +0 -9
- data/test/fixtures/frameworks/rspec_good.rb +0 -9
- data/test/fixtures/frameworks/testunit_bad.rb +0 -9
- data/test/fixtures/frameworks/testunit_good.rb +0 -9
- data/test/fixtures/iso-8859.rb +0 -3
- data/test/fixtures/resultset1.rb +0 -4
- data/test/fixtures/resultset2.rb +0 -5
- data/test/fixtures/sample.rb +0 -16
- data/test/fixtures/utf-8.rb +0 -3
- data/test/helper.rb +0 -34
- data/test/shoulda_macros.rb +0 -19
- data/test/test_1_8_fallbacks.rb +0 -31
- data/test/test_command_guesser.rb +0 -19
- data/test/test_deleted_source.rb +0 -14
- data/test/test_file_list.rb +0 -22
- data/test/test_filters.rb +0 -78
- data/test/test_merge_helpers.rb +0 -105
- data/test/test_result.rb +0 -160
- data/test/test_return_codes.rb +0 -37
- data/test/test_source_file.rb +0 -106
- data/test/test_source_file_line.rb +0 -106
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# SimpleCov Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at simplecov.team@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
data/CONTRIBUTING.md
CHANGED
@@ -1,15 +1,37 @@
|
|
1
|
-
|
1
|
+
## Reporting Issues
|
2
|
+
|
3
|
+
You can report issues at https://github.com/colszowka/simplecov/issues
|
4
|
+
|
5
|
+
Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
|
6
|
+
|
7
|
+
To make sure that we can help you quickly please include and check the following information:
|
8
|
+
|
9
|
+
* Include how you run your tests and which testing framework or frameworks you are running.
|
10
|
+
- please ensure you are requiring and starting SimpleCov before requiring any application code.
|
11
|
+
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
|
12
|
+
For example, if running via RSpec, this would be at the top of your spec_helper.
|
13
|
+
- Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)?
|
14
|
+
* Include the SimpleCov version you are running in your report.
|
15
|
+
* If you are not running the latest version (please check), and you cannot update it,
|
16
|
+
please specify in your report why you can't update to the latest version.
|
17
|
+
* Include your `ruby -e "puts RUBY_DESCRIPTION"`.
|
18
|
+
* Please also specify the gem versions of Rails (if applicable).
|
19
|
+
* Include any other coverage gems you may be using and their versions.
|
20
|
+
|
21
|
+
Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.)
|
22
|
+
|
23
|
+
This is extremely important for narrowing down the cause of your problem.
|
24
|
+
|
25
|
+
Thanks!
|
26
|
+
|
27
|
+
## Making Contributions
|
2
28
|
|
3
29
|
To fetch & test the library for development, do:
|
4
30
|
|
5
31
|
$ git clone https://github.com/colszowka/simplecov.git
|
6
32
|
$ cd simplecov
|
7
33
|
$ bundle
|
8
|
-
$ rake
|
9
|
-
$ rake appraisal
|
10
|
-
|
11
|
-
For more information on the appraisal gem (for testing against multiple gem dependency versions), please see
|
12
|
-
https://github.com/thoughtbot/appraisal/
|
34
|
+
$ bundle exec rake
|
13
35
|
|
14
36
|
If you want to contribute, please:
|
15
37
|
|
@@ -17,4 +39,13 @@ If you want to contribute, please:
|
|
17
39
|
* Make your feature addition or bug fix.
|
18
40
|
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
19
41
|
* **Bonus Points** go out to anyone who also updates `CHANGELOG.md` :)
|
20
|
-
* Send me a pull request on
|
42
|
+
* Send me a pull request on GitHub.
|
43
|
+
|
44
|
+
## Running Individual Tests
|
45
|
+
|
46
|
+
This project uses RSpec and Cucumber. Individual tests can be run like this:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
bundle exec rspec path/to/test.rb
|
50
|
+
bundle exec cucumber path/to/test.feature
|
51
|
+
```
|
data/ISSUE_TEMPLATE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Howdy! Thanks for reporting an issue <3
|
2
|
+
|
3
|
+
Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
|
4
|
+
|
5
|
+
To make sure that we can help you quickly please include and check the following information:
|
6
|
+
|
7
|
+
* Include how you run your tests and which testing framework or frameworks you are running.
|
8
|
+
- please ensure you are requiring and starting SimpleCov before requiring any application code.
|
9
|
+
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
|
10
|
+
For example, if running via RSpec, this would be at the top of your spec_helper.
|
11
|
+
- Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)?
|
12
|
+
* Include the SimpleCov version you are running in your report.
|
13
|
+
* If you are not running the latest version (please check), and you cannot update it,
|
14
|
+
please specify in your report why you can't update to the latest version.
|
15
|
+
* Include your `ruby -e "puts RUBY_DESCRIPTION"`.
|
16
|
+
* Please also specify the gem versions of Rails (if applicable).
|
17
|
+
* Include any other coverage gems you may be using and their versions.
|
18
|
+
|
19
|
+
Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.)
|
20
|
+
|
21
|
+
This is extremely important for narrowing down the cause of your problem.
|
22
|
+
|
23
|
+
Thanks!
|
data/{MIT-LICENSE → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
SimpleCov [![Build Status](https://
|
1
|
+
SimpleCov [![Gem Version](https://badge.fury.io/rb/simplecov.svg)](https://badge.fury.io/rb/simplecov) [![Build Status](https://travis-ci.org/colszowka/simplecov.svg?branch=master)][Continuous Integration] [![Code Climate](https://codeclimate.com/github/colszowka/simplecov.svg)](https://codeclimate.com/github/colszowka/simplecov) [![Inline docs](http://inch-ci.org/github/colszowka/simplecov.svg)](http://inch-ci.org/github/colszowka/simplecov)
|
2
2
|
=========
|
3
|
-
**Code coverage for Ruby
|
3
|
+
**Code coverage for Ruby**
|
4
4
|
|
5
5
|
* [Source Code]
|
6
6
|
* [API documentation]
|
7
7
|
* [Changelog]
|
8
8
|
* [Rubygem]
|
9
|
-
* [Mailing List]
|
10
9
|
* [Continuous Integration]
|
11
10
|
|
12
|
-
[Coverage]:
|
11
|
+
[Coverage]: https://ruby-doc.org/stdlib/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
|
13
12
|
[Source Code]: https://github.com/colszowka/simplecov "Source Code @ GitHub"
|
14
13
|
[API documentation]: http://rubydoc.info/gems/simplecov/frames "RDoc API Documentation at Rubydoc.info"
|
15
14
|
[Configuration]: http://rubydoc.info/gems/simplecov/SimpleCov/Configuration "Configuration options API documentation"
|
@@ -18,92 +17,123 @@ SimpleCov [![Build Status](https://secure.travis-ci.org/colszowka/simplecov.png)
|
|
18
17
|
[Continuous Integration]: http://travis-ci.org/colszowka/simplecov "SimpleCov is built around the clock by travis-ci.org"
|
19
18
|
[Dependencies]: https://gemnasium.com/colszowka/simplecov "SimpleCov dependencies on Gemnasium"
|
20
19
|
[simplecov-html]: https://github.com/colszowka/simplecov-html "SimpleCov HTML Formatter Source Code @ GitHub"
|
21
|
-
[Mailing List]: https://groups.google.com/forum/#!forum/simplecov "Open mailing list for discussion and announcements on Google Groups"
|
22
|
-
[Pledgie]: http://www.pledgie.com/campaigns/18379
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format
|
28
|
-
and display those results, thus giving you a complete code coverage suite that can be set up with just a couple lines of
|
21
|
+
SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Coverage][Coverage] library to gather code
|
22
|
+
coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format,
|
23
|
+
and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of
|
29
24
|
code.
|
25
|
+
SimpleCov/Coverage track covered ruby code, gathering coverage for common templating solutions like erb, slim and haml is not supported.
|
30
26
|
|
31
|
-
In most cases, you'll want overall coverage results for your projects, including all types of tests,
|
32
|
-
etc. SimpleCov automatically takes care of this by caching and
|
27
|
+
In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features,
|
28
|
+
etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your
|
33
29
|
report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
|
34
30
|
|
35
|
-
The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html] but will be installed and
|
36
|
-
automatically when you launch SimpleCov. If you're curious, you can find it [on
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Getting started
|
41
|
-
---------------
|
42
|
-
|
43
|
-
1. Add SimpleCov to your `Gemfile` and `bundle install`:
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
gem 'simplecov', :require => false, :group => :test
|
47
|
-
```
|
31
|
+
The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and
|
32
|
+
configured automatically when you launch SimpleCov. If you're curious, you can find it [on GitHub, too][simplecov-html].
|
48
33
|
|
49
|
-
2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb` (*or `spec_helper.rb`, cucumber `env.rb`, or whatever
|
50
|
-
your preferred test framework uses*):
|
51
34
|
|
52
|
-
|
53
|
-
require 'simplecov'
|
54
|
-
SimpleCov.start
|
35
|
+
## Contact
|
55
36
|
|
56
|
-
|
57
|
-
```
|
37
|
+
*Code and Bug Reports*
|
58
38
|
|
59
|
-
|
60
|
-
|
61
|
-
|
39
|
+
* [Issue Tracker](https://github.com/colszowka/simplecov/issues)
|
40
|
+
* See [CONTRIBUTING](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md) for how to contribute along
|
41
|
+
with some common problems to check out before creating an issue.
|
62
42
|
|
63
|
-
|
64
|
-
process (i.e. a JSON API endpoint) via a separate test process (i.e. when using Selenium) where you want to see all
|
65
|
-
code executed by the `rails server`, and not just code executed in your actual test files, you'll want to add something
|
66
|
-
like this to the top of `script/rails`:
|
43
|
+
*Questions, Problems, Suggestions, etc.*
|
67
44
|
|
68
|
-
|
69
|
-
|
70
|
-
require 'simplecov'
|
71
|
-
SimpleCov.start 'rails'
|
72
|
-
puts "required simplecov"
|
73
|
-
end
|
74
|
-
```
|
45
|
+
* [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements
|
46
|
+
on Google Groups"
|
75
47
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
coverage
|
48
|
+
Getting started
|
49
|
+
---------------
|
50
|
+
1. Add SimpleCov to your `Gemfile` and `bundle install`:
|
81
51
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
```
|
52
|
+
```ruby
|
53
|
+
gem 'simplecov', require: false, group: :test
|
54
|
+
```
|
55
|
+
2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb`
|
56
|
+
(*or `spec_helper.rb`, `rails_helper`, cucumber `env.rb`, or whatever your preferred test
|
57
|
+
framework uses*):
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
require 'simplecov'
|
61
|
+
SimpleCov.start
|
62
|
+
|
63
|
+
# Previous content of test helper now starts here
|
64
|
+
```
|
65
|
+
|
66
|
+
**Note:** If SimpleCov starts after your application code is already loaded
|
67
|
+
(via `require`), it won't be able to track your files and their coverage!
|
68
|
+
The `SimpleCov.start` **must** be issued **before any of your application
|
69
|
+
code is required!**
|
70
|
+
|
71
|
+
SimpleCov must be running in the process that you want the code coverage
|
72
|
+
analysis to happen on. When testing a server process (e.g. a JSON API
|
73
|
+
endpoint) via a separate test process (e.g. when using Selenium) where you
|
74
|
+
want to see all code executed by the `rails server`, and not just code
|
75
|
+
executed in your actual test files, you'll want to add something like this
|
76
|
+
to the top of `bin/rails`, but below the "shebang" line (`#! /usr/bin/env
|
77
|
+
ruby`):
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
if ENV['RAILS_ENV'] == 'test'
|
81
|
+
require 'simplecov'
|
82
|
+
SimpleCov.start 'rails'
|
83
|
+
puts "required simplecov"
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
3. Run your full test suite to see the percent coverage that your application has.
|
88
|
+
4. After running your tests, open `coverage/index.html` in the browser of your choice. For example, in a Mac Terminal,
|
89
|
+
run the following command from your application's root directory:
|
90
|
+
|
91
|
+
```
|
92
|
+
open coverage/index.html
|
93
|
+
```
|
94
|
+
in a debian/ubuntu Terminal,
|
95
|
+
|
96
|
+
```
|
97
|
+
xdg-open coverage/index.html
|
98
|
+
```
|
99
|
+
|
100
|
+
**Note:** [This guide](https://dwheeler.com/essays/open-files-urls.html) can help if you're unsure which command your particular
|
101
|
+
operating system requires.
|
102
|
+
|
103
|
+
5. Add the following to your `.gitignore` file to ensure that coverage results
|
104
|
+
are not tracked by Git (optional):
|
105
|
+
|
106
|
+
```
|
107
|
+
echo "coverage" >> .gitignore
|
108
|
+
```
|
109
|
+
Or if you use Windows:
|
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
|
+
```
|
90
122
|
|
91
123
|
## Example output
|
92
124
|
|
93
125
|
**Coverage results report, fully browsable locally with sorting and much more:**
|
94
126
|
|
95
|
-
![SimpleCov coverage report](
|
127
|
+
![SimpleCov coverage report](https://cloud.githubusercontent.com/assets/137793/17071162/db6f253e-502d-11e6-9d84-e40c3d75f333.png)
|
96
128
|
|
97
129
|
|
98
130
|
**Source file coverage details view:**
|
99
131
|
|
100
|
-
![SimpleCov source file detail view](
|
101
|
-
|
102
|
-
|
132
|
+
![SimpleCov source file detail view](https://cloud.githubusercontent.com/assets/137793/17071163/db6f9f0a-502d-11e6-816c-edb2c66fad8d.png)
|
103
133
|
|
104
134
|
## Use it with any framework!
|
105
135
|
|
106
|
-
|
136
|
+
Similarly to the usage with Test::Unit described above, the only thing you have to do is to add the SimpleCov
|
107
137
|
config to the very top of your Cucumber/RSpec/whatever setup file.
|
108
138
|
|
109
139
|
Add the setup code to the **top** of `features/support/env.rb` (for Cucumber) or `spec/spec_helper.rb` (for RSpec).
|
@@ -114,8 +144,9 @@ require 'simplecov'
|
|
114
144
|
SimpleCov.start 'rails'
|
115
145
|
```
|
116
146
|
|
117
|
-
You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov
|
118
|
-
care what kind of framework it is running in
|
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.
|
119
150
|
|
120
151
|
### Notes on specific frameworks and test utilities
|
121
152
|
|
@@ -123,69 +154,75 @@ For some frameworks and testing tools there are quirks and problems you might wa
|
|
123
154
|
to use SimpleCov with them. Here's an overview of the known ones:
|
124
155
|
|
125
156
|
<table>
|
126
|
-
<tr><th>Framework</th><th>Notes</th><th>Issue
|
127
|
-
<tr>
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
</
|
139
|
-
</
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
</
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
</
|
177
|
-
<
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
</
|
188
|
-
|
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/colszowka/simplecov/issues/64">#64</a> &
|
170
|
+
<a href="https://github.com/colszowka/simplecov/pull/185">#185</a>
|
171
|
+
</td>
|
172
|
+
</tr>
|
173
|
+
<tr>
|
174
|
+
<th>
|
175
|
+
RubyMine
|
176
|
+
</th>
|
177
|
+
<td>
|
178
|
+
The <a href="https://www.jetbrains.com/ruby/">RubyMine IDE</a> has
|
179
|
+
built-in support for SimpleCov's coverage reports, though you might need
|
180
|
+
to explicitly set the output root using `SimpleCov.root('foo/bar/baz')`
|
181
|
+
</td>
|
182
|
+
<td>
|
183
|
+
<a href="https://github.com/colszowka/simplecov/issues/95">#95</a>
|
184
|
+
</td>
|
185
|
+
</tr>
|
186
|
+
<tr>
|
187
|
+
<th>
|
188
|
+
Spork
|
189
|
+
</th>
|
190
|
+
<td>
|
191
|
+
Because of how Spork works internally (using preforking), there used to
|
192
|
+
be trouble when using SimpleCov with it, but that has apparently been
|
193
|
+
resolved with a specific configuration strategy. See <a
|
194
|
+
href="https://github.com/colszowka/simplecov/issues/42#issuecomment-4440284">this</a>
|
195
|
+
comment.
|
196
|
+
</td>
|
197
|
+
<td>
|
198
|
+
<a href="https://github.com/colszowka/simplecov/issues/42#issuecomment-4440284">#42</a>
|
199
|
+
</td>
|
200
|
+
</tr>
|
201
|
+
<tr>
|
202
|
+
<th>
|
203
|
+
Spring
|
204
|
+
</th>
|
205
|
+
<td>
|
206
|
+
<a href="#want-to-use-spring-with-simplecov">See section below.</a>
|
207
|
+
</td>
|
208
|
+
<td>
|
209
|
+
<a href="https://github.com/colszowka/simplecov/issues/381">#381</a>
|
210
|
+
</td>
|
211
|
+
</tr>
|
212
|
+
<tr>
|
213
|
+
<th>
|
214
|
+
Test/Unit
|
215
|
+
</th>
|
216
|
+
<td>
|
217
|
+
Test Unit 2 used to mess with ARGV, leading to a failure to detect the
|
218
|
+
test process name in SimpleCov. <code>test-unit</code> releases 2.4.3+
|
219
|
+
(Dec 11th, 2011) should have this problem resolved.
|
220
|
+
</td>
|
221
|
+
<td>
|
222
|
+
<a href="https://github.com/colszowka/simplecov/issues/45">#45</a> &
|
223
|
+
<a href="https://github.com/test-unit/test-unit/pull/12">test-unit/test-unit#12</a>
|
224
|
+
</td>
|
225
|
+
</tr>
|
189
226
|
</table>
|
190
227
|
|
191
228
|
## Configuring SimpleCov
|
@@ -194,36 +231,35 @@ to use SimpleCov with them. Here's an overview of the known ones:
|
|
194
231
|
|
195
232
|
* The most common way is to configure it directly in your start block:
|
196
233
|
|
197
|
-
```ruby
|
198
|
-
SimpleCov.start do
|
199
|
-
|
200
|
-
end
|
201
|
-
```
|
202
|
-
|
234
|
+
```ruby
|
235
|
+
SimpleCov.start do
|
236
|
+
some_config_option 'foo'
|
237
|
+
end
|
238
|
+
```
|
203
239
|
* You can also set all configuration options directly:
|
204
240
|
|
205
|
-
```ruby
|
206
|
-
SimpleCov.some_config_option 'foo'
|
207
|
-
```
|
241
|
+
```ruby
|
242
|
+
SimpleCov.some_config_option 'foo'
|
243
|
+
```
|
244
|
+
* If you do not want to start coverage immediately after launch or want to add additional configuration later on in a
|
245
|
+
concise way, use:
|
208
246
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
215
|
-
```
|
247
|
+
```ruby
|
248
|
+
SimpleCov.configure do
|
249
|
+
some_config_option 'foo'
|
250
|
+
end
|
251
|
+
```
|
216
252
|
|
217
253
|
Please check out the [Configuration] API documentation to find out what you can customize.
|
218
254
|
|
219
|
-
|
220
255
|
## Using .simplecov for centralized config
|
221
256
|
|
222
|
-
If you use SimpleCov to merge multiple test suite results (
|
223
|
-
set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
|
257
|
+
If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cucumber) into a single report, you'd
|
258
|
+
normally have to set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
|
224
259
|
|
225
|
-
To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the
|
226
|
-
test setup helper and move the `SimpleCov.start` code with all your
|
260
|
+
To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the
|
261
|
+
`require 'simplecov'` in each test setup helper (**at the top**) and move the `SimpleCov.start` code with all your
|
262
|
+
custom config options into `.simplecov`:
|
227
263
|
|
228
264
|
```ruby
|
229
265
|
# test/test_helper.rb
|
@@ -238,19 +274,69 @@ SimpleCov.start 'rails' do
|
|
238
274
|
end
|
239
275
|
```
|
240
276
|
|
277
|
+
Using `.simplecov` rather than separately requiring SimpleCov multiple times is recommended if you are merging multiple
|
278
|
+
test frameworks like Cucumber and RSpec that rely on each other, as invoking SimpleCov multiple times can cause coverage
|
279
|
+
information to be lost.
|
280
|
+
|
281
|
+
## Branch coverage (ruby "~> 2.5")
|
282
|
+
Add branch coverage measurement statistics to your results. Supported in CRuby versions 2.5+.
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
# or in configure or just SimpleCov.enable_coverage :branch
|
286
|
+
SimpleCov.start do
|
287
|
+
enable_coverage :branch
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
Branch coverage is a feature introduced in Ruby 2.5 concerning itself with whether a
|
292
|
+
particular branch of a condition had been executed. Line coverage on the other hand
|
293
|
+
is only interested in whether a line of code has been executed.
|
294
|
+
|
295
|
+
This comes in handy for instance for one line conditionals:
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
number.odd? ? "odd" : "even"
|
299
|
+
```
|
300
|
+
|
301
|
+
In line coverage this line would always be marked as executed but you'd never know if both
|
302
|
+
conditions were met. Guard clauses have a similar story:
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
return if number.odd?
|
306
|
+
|
307
|
+
# more code
|
308
|
+
```
|
309
|
+
|
310
|
+
If all the code in that method was covered you'd never know if the guard clause was ever
|
311
|
+
triggered with line coverage as just evaluating the condition marks it as covered.
|
312
|
+
|
313
|
+
In the HTML report the lines of code will be annotated like `hit_count, positive_or_negative_branch`:
|
314
|
+
|
315
|
+
* `2, +` - the positive branch was executed twice
|
316
|
+
* `0, -` - the negative branch was never executed
|
317
|
+
|
318
|
+
**Is branch coverage strictly better?** No. Branch coverage really only concerns itself with
|
319
|
+
conditionals - meaning coverage of sequential code is of no interest to it. A file without
|
320
|
+
conditional logic will have no branch coverage data and SimpleCov will report 0 of 0
|
321
|
+
branches covered as 100% (as everything that can be covered was covered).
|
322
|
+
|
323
|
+
Hence, we recommend looking at both metrics together. Branch coverage might also be a good
|
324
|
+
overall metric to look at - while you might be missing only 10% of your lines that might
|
325
|
+
account for 50% of your branches for instance.
|
326
|
+
|
241
327
|
## Filters
|
242
328
|
|
243
|
-
Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
|
244
|
-
OUTSIDE of your project's root directory - otherwise you'd end up with
|
245
|
-
gems you are using.
|
329
|
+
Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
|
330
|
+
files OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source
|
331
|
+
files in the gems you are using.
|
246
332
|
|
247
|
-
|
333
|
+
You can define your own to remove things like configuration files, tests or whatever you don't need in your coverage
|
248
334
|
report.
|
249
335
|
|
250
336
|
### Defining custom filters
|
251
337
|
|
252
|
-
You can currently define a filter using either a String (that will then be Regexp-matched against each source
|
253
|
-
a block or by passing in your own Filter class.
|
338
|
+
You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source
|
339
|
+
file's path), a block or by passing in your own Filter class.
|
254
340
|
|
255
341
|
#### String filter
|
256
342
|
|
@@ -262,6 +348,16 @@ end
|
|
262
348
|
|
263
349
|
This simple string filter will remove all files that match "/test/" in their path.
|
264
350
|
|
351
|
+
#### Regex filter
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
SimpleCov.start do
|
355
|
+
add_filter %r{^/test/}
|
356
|
+
end
|
357
|
+
```
|
358
|
+
|
359
|
+
This simple regex filter will remove all files that start with /test/ in their path.
|
360
|
+
|
265
361
|
#### Block filter
|
266
362
|
|
267
363
|
```ruby
|
@@ -272,9 +368,10 @@ SimpleCov.start do
|
|
272
368
|
end
|
273
369
|
```
|
274
370
|
|
275
|
-
Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be
|
276
|
-
from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to
|
277
|
-
methods available to you. In the above example, the filter will remove all files that have less
|
371
|
+
Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be
|
372
|
+
removed from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to
|
373
|
+
learn about the methods available to you. In the above example, the filter will remove all files that have less than 5
|
374
|
+
lines of code.
|
278
375
|
|
279
376
|
#### Custom filter class
|
280
377
|
|
@@ -288,17 +385,63 @@ end
|
|
288
385
|
SimpleCov.add_filter LineFilter.new(5)
|
289
386
|
```
|
290
387
|
|
291
|
-
Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method
|
292
|
-
the filter, a true return value from this method will result in the removal of the
|
293
|
-
is being set in the SimpleCov::Filter initialize method and thus is set to
|
388
|
+
Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method
|
389
|
+
'matches?(source_file)'. When running the filter, a true return value from this method will result in the removal of the
|
390
|
+
given source_file. The filter_argument method is being set in the SimpleCov::Filter initialize method and thus is set to
|
391
|
+
5 in this example.
|
392
|
+
|
393
|
+
#### Array filter
|
394
|
+
|
395
|
+
```ruby
|
396
|
+
SimpleCov.start do
|
397
|
+
proc = Proc.new { |source_file| false }
|
398
|
+
add_filter ["string", /regex/, proc, LineFilter.new(5)]
|
399
|
+
end
|
400
|
+
```
|
401
|
+
|
402
|
+
You can pass in an array containing any of the other filter types.
|
403
|
+
|
404
|
+
#### Ignoring/skipping code
|
405
|
+
|
406
|
+
You can exclude code from the coverage report by wrapping it in `# :nocov:`.
|
407
|
+
|
408
|
+
```ruby
|
409
|
+
# :nocov:
|
410
|
+
def skip_this_method
|
411
|
+
never_reached
|
412
|
+
end
|
413
|
+
# :nocov:
|
414
|
+
```
|
415
|
+
|
416
|
+
The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/colszowka/simplecov/blob/master/features/config_nocov_token.feature)
|
417
|
+
|
418
|
+
**Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If
|
419
|
+
you appropriately test the public interface of your classes and objects you should automatically get full coverage of
|
420
|
+
your private methods.
|
421
|
+
|
422
|
+
## Default root filter and coverage for things outside of it
|
294
423
|
|
424
|
+
By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want
|
425
|
+
to include coverage reports for things you include as a gem, for example a Rails Engine.
|
426
|
+
|
427
|
+
Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/colszowka/simplecov/issues/221)
|
428
|
+
that shows how you can achieve just that:
|
429
|
+
|
430
|
+
```ruby
|
431
|
+
SimpleCov.start :rails do
|
432
|
+
filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults
|
433
|
+
add_filter do |src|
|
434
|
+
!(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /my_engine/
|
435
|
+
end
|
436
|
+
end
|
437
|
+
```
|
295
438
|
|
296
439
|
## Groups
|
297
440
|
|
298
|
-
You can separate your source files into groups. For example, in a
|
299
|
-
Models, Controllers, Helpers,
|
300
|
-
filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering
|
301
|
-
which exclude files from results when the filter results in a true value.
|
441
|
+
You can separate your source files into groups. For example, in a Rails app, you'll want to have separate listings for
|
442
|
+
Models, Controllers, Helpers, and Libs. Group definition works similarly to Filters (and also accepts custom
|
443
|
+
filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering
|
444
|
+
results, which exclude files from results when the filter results in a true value.
|
302
445
|
|
303
446
|
Add your groups with:
|
304
447
|
|
@@ -309,16 +452,17 @@ SimpleCov.start do
|
|
309
452
|
add_group "Long files" do |src_file|
|
310
453
|
src_file.lines.count > 100
|
311
454
|
end
|
455
|
+
add_group "Multiple Files", ["app/models", "app/controllers"] # You can also pass in an array
|
312
456
|
add_group "Short files", LineFilter.new(5) # Using the LineFilter class defined in Filters section above
|
313
457
|
end
|
314
458
|
```
|
315
459
|
|
316
460
|
## Merging results
|
317
461
|
|
318
|
-
|
462
|
+
You normally want to have your coverage analyzed across ALL of your test suites, right?
|
319
463
|
|
320
464
|
Simplecov automatically caches coverage results in your (coverage_path)/.resultset.json. Those results will then
|
321
|
-
be automatically merged when generating the result, so when coverage is set up properly for
|
465
|
+
be automatically merged when generating the result, so when coverage is set up properly for Cucumber and your
|
322
466
|
unit / functional / integration tests, all of those test suites will be taken into account when building the
|
323
467
|
coverage report.
|
324
468
|
|
@@ -326,17 +470,17 @@ There are two things to note here though:
|
|
326
470
|
|
327
471
|
### Test suite names
|
328
472
|
|
329
|
-
|
330
|
-
on. This should work fine for Unit Tests, RSpec and Cucumber. If it fails, it will use the shell
|
331
|
-
that invoked the test suite as a command name.
|
473
|
+
SimpleCov tries to guess the name of the currently running test suite based upon the shell command the tests
|
474
|
+
are running on. This should work fine for Unit Tests, RSpec, and Cucumber. If it fails, it will use the shell
|
475
|
+
command that invoked the test suite as a command name.
|
332
476
|
|
333
|
-
If you have some non-standard setup and still want nicely labeled test suites, you have to give Simplecov a
|
334
|
-
name of the currently running test suite is. You can do so by specifying
|
335
|
-
part of your specific suite.
|
477
|
+
If you have some non-standard setup and still want nicely labeled test suites, you have to give Simplecov a
|
478
|
+
cue as to what the name of the currently running test suite is. You can do so by specifying
|
479
|
+
`SimpleCov.command_name` in one test file that is part of your specific suite.
|
336
480
|
|
337
|
-
|
338
|
-
the structure of those projects is. You can apply this accordingly to the RSpecs in your
|
339
|
-
you could do something like this:
|
481
|
+
To customize the suite names on a Rails app (yeah, sorry for being Rails-biased, but everyone knows what
|
482
|
+
the structure of those projects is. You can apply this accordingly to the RSpecs in your
|
483
|
+
Outlook-WebDAV-Calendar-Sync gem), you could do something like this:
|
340
484
|
|
341
485
|
```ruby
|
342
486
|
# test/unit/some_test.rb
|
@@ -352,30 +496,50 @@ SimpleCov.command_name "test:integration"
|
|
352
496
|
SimpleCov.command_name "features"
|
353
497
|
```
|
354
498
|
|
355
|
-
Note that this has
|
356
|
-
some_test.rb is
|
499
|
+
Note that this only has to be invoked ONCE PER TEST SUITE, so even if you have 200 unit test files,
|
500
|
+
specifying it in `some_test.rb` is enough.
|
501
|
+
|
502
|
+
Last but not least **if multiple suites resolve to the same `command_name`** be aware that the coverage results **will
|
503
|
+
clobber each other instead of being merged**. SimpleCov is smart enough to detect unique names for the most common
|
504
|
+
setups, but if you have more than one test suite that doesn't follow a common pattern then you will want to manually
|
505
|
+
ensure that each suite gets a unique `command_name`.
|
506
|
+
|
507
|
+
If you are running tests in parallel each process has the potential to clobber results from the other test processes.
|
508
|
+
If you are relying on the default `command_name` then SimpleCov will attempt to detect and avoid parallel test suite
|
509
|
+
`command_name` collisions based on the presence of `ENV['PARALLEL_TEST_GROUPS']` and `ENV['TEST_ENV_NUMBER']`. If your
|
510
|
+
parallel test runner does not set one or both of these then *you must* set a `command_name` and ensure that it is unique
|
511
|
+
per process (eg. `command_name "Unit Tests PID #{$$}"`).
|
512
|
+
|
513
|
+
If you are using parallel_tests, you must incorporate `TEST_ENV_NUMBER` into the command name yourself, in
|
514
|
+
order for SimpleCov to merge the results correctly. For example:
|
515
|
+
|
516
|
+
```ruby
|
517
|
+
# spec/spec_helper.rb
|
518
|
+
SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '')
|
519
|
+
```
|
357
520
|
|
358
521
|
[simplecov-html] prints the used test suites in the footer of the generated coverage report.
|
359
522
|
|
360
523
|
### Timeout for merge
|
361
524
|
|
362
525
|
Of course, your cached coverage data is likely to become invalid at some point. Thus, result sets that are older than
|
363
|
-
SimpleCov.merge_timeout will not be used any more. By default, the timeout is 600 seconds (10 minutes), and you can
|
526
|
+
`SimpleCov.merge_timeout` will not be used any more. By default, the timeout is 600 seconds (10 minutes), and you can
|
364
527
|
raise (or lower) it by specifying `SimpleCov.merge_timeout 3600` (1 hour), or, inside a configure/start block, with
|
365
|
-
just
|
528
|
+
just `merge_timeout 3600`.
|
366
529
|
|
367
530
|
You can deactivate merging altogether with `SimpleCov.use_merging false`.
|
368
531
|
|
369
|
-
|
370
532
|
## Running coverage only on demand
|
371
533
|
|
372
|
-
The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (
|
373
|
-
only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you
|
374
|
-
it doesn't do your test speed any harm and you're always equipped with the latest and greatest
|
534
|
+
The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed
|
535
|
+
drop was only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you
|
536
|
+
run your tests because it doesn't do your test speed any harm and you're always equipped with the latest and greatest
|
537
|
+
coverage results.
|
375
538
|
|
376
539
|
Because of this, SimpleCov has no explicit built-in mechanism to run coverage only on demand.
|
377
540
|
|
378
|
-
However, you can still accomplish this very easily by introducing
|
541
|
+
However, you can still accomplish this very easily by introducing an ENV variable conditional into your SimpleCov setup
|
542
|
+
block, like this:
|
379
543
|
|
380
544
|
```ruby
|
381
545
|
SimpleCov.start if ENV["COVERAGE"]
|
@@ -387,11 +551,25 @@ Then, SimpleCov will only run if you execute your tests like this:
|
|
387
551
|
COVERAGE=true rake test
|
388
552
|
```
|
389
553
|
|
554
|
+
## Errors and exit statuses
|
555
|
+
|
556
|
+
To aid in debugging issues, if an error is raised, SimpleCov will print a message to `STDERR`
|
557
|
+
with the exit status of the error, like:
|
558
|
+
|
559
|
+
```
|
560
|
+
SimpleCov failed with exit 1
|
561
|
+
```
|
562
|
+
|
563
|
+
This `STDERR` message can be disabled with:
|
564
|
+
|
565
|
+
```
|
566
|
+
SimpleCov.print_error_status = false
|
567
|
+
```
|
390
568
|
|
391
569
|
## Profiles
|
392
570
|
|
393
|
-
By default,
|
394
|
-
root. To save
|
571
|
+
By default, SimpleCov's only config assumption is that you only want coverage reports for files inside your project
|
572
|
+
root. To save yourself from repetitive configuration, you can use predefined blocks of configuration, called 'profiles',
|
395
573
|
or define your own.
|
396
574
|
|
397
575
|
You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov
|
@@ -406,17 +584,16 @@ SimpleCov.profiles.define 'rails' do
|
|
406
584
|
add_group 'Models', 'app/models'
|
407
585
|
add_group 'Helpers', 'app/helpers'
|
408
586
|
add_group 'Libraries', 'lib'
|
409
|
-
add_group 'Plugins', 'vendor/plugins'
|
410
587
|
end
|
411
588
|
```
|
412
589
|
|
413
|
-
As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch
|
590
|
+
As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch SimpleCov with:
|
414
591
|
|
415
592
|
```ruby
|
416
593
|
SimpleCov.start 'rails'
|
417
594
|
```
|
418
595
|
|
419
|
-
|
596
|
+
or
|
420
597
|
|
421
598
|
```ruby
|
422
599
|
SimpleCov.start 'rails' do
|
@@ -426,8 +603,8 @@ end
|
|
426
603
|
|
427
604
|
### Custom profiles
|
428
605
|
|
429
|
-
You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an
|
430
|
-
profile and customize it so you can reuse it in unit tests and
|
606
|
+
You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an
|
607
|
+
existing profile and customize it so you can reuse it in unit tests and Cucumber features. For example:
|
431
608
|
|
432
609
|
```ruby
|
433
610
|
# lib/simplecov_custom_profile.rb
|
@@ -446,10 +623,9 @@ require 'simplecov_custom_profile'
|
|
446
623
|
SimpleCov.start 'myprofile'
|
447
624
|
```
|
448
625
|
|
449
|
-
|
450
626
|
## Customizing exit behaviour
|
451
627
|
|
452
|
-
You can define what
|
628
|
+
You can define what SimpleCov should do when your test suite finishes by customizing the at_exit hook:
|
453
629
|
|
454
630
|
```ruby
|
455
631
|
SimpleCov.at_exit do
|
@@ -467,6 +643,15 @@ You can define the minimum coverage percentage expected. SimpleCov will return n
|
|
467
643
|
SimpleCov.minimum_coverage 90
|
468
644
|
```
|
469
645
|
|
646
|
+
### Minimum coverage by file
|
647
|
+
|
648
|
+
You can define the minimum coverage by file percentage expected. SimpleCov will return non-zero if unmet. This is useful
|
649
|
+
to help ensure coverage is relatively consistent, rather than being skewed by particularly good or bad areas of the code.
|
650
|
+
|
651
|
+
```ruby
|
652
|
+
SimpleCov.minimum_coverage_by_file 80
|
653
|
+
```
|
654
|
+
|
470
655
|
### Maximum coverage drop
|
471
656
|
|
472
657
|
You can define the maximum coverage drop percentage at once. SimpleCov will return non-zero if exceeded.
|
@@ -491,66 +676,100 @@ You can use your own formatter with:
|
|
491
676
|
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
|
492
677
|
```
|
493
678
|
|
494
|
-
When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result),
|
495
|
-
being an instance of SimpleCov::Result. Do whatever your wish with that!
|
679
|
+
When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result),
|
680
|
+
"result" being an instance of SimpleCov::Result. Do whatever your wish with that!
|
496
681
|
|
497
682
|
|
498
683
|
## Using multiple formatters
|
499
684
|
|
500
|
-
|
685
|
+
As of SimpleCov 0.9, you can specify multiple result formats:
|
501
686
|
|
502
687
|
```ruby
|
503
|
-
SimpleCov.
|
688
|
+
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
|
504
689
|
SimpleCov::Formatter::HTMLFormatter,
|
505
690
|
SimpleCov::Formatter::CSVFormatter,
|
506
|
-
]
|
691
|
+
])
|
507
692
|
```
|
508
693
|
|
509
|
-
## Available formatters
|
694
|
+
## Available formatters, editor integrations and hosted services
|
695
|
+
|
696
|
+
* [Open Source formatter and integration plugins for SimpleCov](doc/alternate-formatters.md)
|
697
|
+
* [Editor Integration](doc/editor-integration.md)
|
698
|
+
* [Hosted (commercial) services](doc/commercial-services.md)
|
699
|
+
|
700
|
+
## Ruby version compatibility
|
701
|
+
|
702
|
+
SimpleCov is built in [Continuous Integration] on Ruby 2.4+ as well as JRuby 9.2+.
|
703
|
+
|
704
|
+
Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
|
705
|
+
|
706
|
+
## Want to find dead code in production?
|
707
|
+
|
708
|
+
Try [Coverband](https://github.com/danmayer/coverband).
|
510
709
|
|
511
|
-
|
512
|
-
available:
|
710
|
+
## Want to use Spring with SimpleCov?
|
513
711
|
|
514
|
-
|
515
|
-
|
712
|
+
If you're using [Spring](https://github.com/rails/spring) to speed up test suite runs and want to run SimpleCov along
|
713
|
+
with them, you'll find that it often misreports coverage with the default config due to some sort of eager loading
|
714
|
+
issue. Don't despair!
|
516
715
|
|
517
|
-
|
716
|
+
One solution is to [explicitly call eager
|
717
|
+
load](https://github.com/colszowka/simplecov/issues/381#issuecomment-347651728)
|
718
|
+
in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
|
518
719
|
|
519
|
-
|
520
|
-
|
720
|
+
```ruby
|
721
|
+
require 'simplecov'
|
722
|
+
SimpleCov.start 'rails'
|
723
|
+
Rails.application.eager_load!
|
724
|
+
```
|
521
725
|
|
522
|
-
|
726
|
+
Alternatively, you could disable Spring while running SimpleCov:
|
523
727
|
|
524
|
-
|
525
|
-
|
728
|
+
```
|
729
|
+
DISABLE_SPRING=1 rake test
|
730
|
+
```
|
526
731
|
|
527
|
-
|
732
|
+
Or you could remove `gem 'spring'` from your `Gemfile`.
|
528
733
|
|
529
|
-
|
530
|
-
*by [Michael Grosser](http://grosser.it)*
|
734
|
+
## Troubleshooting
|
531
735
|
|
532
|
-
|
736
|
+
The **most common problem is that simplecov isn't required and started before everything else**. In order to track
|
737
|
+
coverage for your whole application **simplecov needs to be the first one** so that it (and the underlying coverage
|
738
|
+
library) can subsequently track loaded files and their usage.
|
533
739
|
|
534
|
-
|
535
|
-
|
740
|
+
If you are missing coverage for some code a simple trick is to put a puts statement in there and right after
|
741
|
+
`SimpleCov.start` so you can see if the file really was loaded after simplecov was started.
|
536
742
|
|
537
|
-
|
743
|
+
```ruby
|
744
|
+
# my_code.rb
|
745
|
+
class MyCode
|
538
746
|
|
539
|
-
|
540
|
-
*by Matt Hale*
|
747
|
+
puts "MyCode is being loaded!"
|
541
748
|
|
542
|
-
|
749
|
+
def my_method
|
750
|
+
# ...
|
751
|
+
end
|
752
|
+
end
|
543
753
|
|
544
|
-
|
754
|
+
# spec_helper.rb/rails_helper.rb/test_helper.rb/.simplecov whatever
|
755
|
+
|
756
|
+
SimpleCov.start
|
757
|
+
puts "SimpleCov started successfully!"
|
758
|
+
```
|
759
|
+
|
760
|
+
Now when you run your test suite and you see:
|
761
|
+
|
762
|
+
```
|
763
|
+
SimpleCov started successfully!
|
764
|
+
MyCode is being loaded!
|
765
|
+
```
|
545
766
|
|
546
|
-
|
767
|
+
then it's good otherwise you likely have a problem :)
|
547
768
|
|
548
|
-
|
549
|
-
including Rubinius and JRuby, in [Continuous Integration], but this happens only to ensure that SimpleCov does not make your
|
550
|
-
test suite crash right now. Whether SimpleCov will support JRuby/Rubinius in the future depends solely on whether those Ruby
|
551
|
-
interpreters add the coverage library.
|
769
|
+
## Code of Conduct
|
552
770
|
|
553
|
-
|
771
|
+
Everyone participating in this project's development, issue trackers and other channels is expected to follow our
|
772
|
+
[Code of Conduct](./CODE_OF_CONDUCT.md)
|
554
773
|
|
555
774
|
## Contributing
|
556
775
|
|
@@ -562,4 +781,4 @@ Thanks to Aaron Patterson for the original idea for this!
|
|
562
781
|
|
563
782
|
## Copyright
|
564
783
|
|
565
|
-
Copyright (c) 2010-
|
784
|
+
Copyright (c) 2010-2017 Christoph Olszowka. See MIT-LICENSE for details.
|