simplecov 0.15.1 → 0.18.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +98 -1
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +12 -9
  5. data/ISSUE_TEMPLATE.md +23 -0
  6. data/{MIT-LICENSE → LICENSE} +0 -0
  7. data/README.md +300 -115
  8. data/doc/alternate-formatters.md +20 -0
  9. data/lib/simplecov.rb +298 -45
  10. data/lib/simplecov/combine.rb +30 -0
  11. data/lib/simplecov/combine/branches_combiner.rb +32 -0
  12. data/lib/simplecov/combine/files_combiner.rb +24 -0
  13. data/lib/simplecov/combine/lines_combiner.rb +43 -0
  14. data/lib/simplecov/combine/results_combiner.rb +60 -0
  15. data/lib/simplecov/command_guesser.rb +8 -3
  16. data/lib/simplecov/configuration.rb +95 -8
  17. data/lib/simplecov/defaults.rb +13 -80
  18. data/lib/simplecov/exit_codes.rb +2 -0
  19. data/lib/simplecov/file_list.rb +32 -3
  20. data/lib/simplecov/filter.rb +5 -2
  21. data/lib/simplecov/formatter.rb +2 -0
  22. data/lib/simplecov/formatter/multi_formatter.rb +4 -2
  23. data/lib/simplecov/formatter/simple_formatter.rb +6 -4
  24. data/lib/simplecov/last_run.rb +5 -1
  25. data/lib/simplecov/lines_classifier.rb +21 -5
  26. data/lib/simplecov/load_global_config.rb +2 -0
  27. data/lib/simplecov/no_defaults.rb +2 -0
  28. data/lib/simplecov/profiles.rb +11 -7
  29. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  30. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  31. data/lib/simplecov/profiles/rails.rb +18 -0
  32. data/lib/simplecov/profiles/root_filter.rb +10 -0
  33. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  34. data/lib/simplecov/result.rb +41 -6
  35. data/lib/simplecov/result_adapter.rb +30 -0
  36. data/lib/simplecov/result_merger.rb +20 -11
  37. data/lib/simplecov/simulate_coverage.rb +29 -0
  38. data/lib/simplecov/source_file.rb +190 -109
  39. data/lib/simplecov/source_file/branch.rb +84 -0
  40. data/lib/simplecov/source_file/line.rb +72 -0
  41. data/lib/simplecov/useless_results_remover.rb +16 -0
  42. data/lib/simplecov/version.rb +3 -1
  43. metadata +44 -162
  44. data/.gitignore +0 -31
  45. data/.rspec +0 -3
  46. data/.rubocop.yml +0 -88
  47. data/.travis.yml +0 -29
  48. data/.yardopts +0 -1
  49. data/Gemfile +0 -38
  50. data/Rakefile +0 -39
  51. data/cucumber.yml +0 -13
  52. data/features/config_autoload.feature +0 -46
  53. data/features/config_command_name.feature +0 -45
  54. data/features/config_coverage_dir.feature +0 -33
  55. data/features/config_deactivate_merging.feature +0 -42
  56. data/features/config_formatters.feature +0 -77
  57. data/features/config_merge_timeout.feature +0 -39
  58. data/features/config_nocov_token.feature +0 -79
  59. data/features/config_profiles.feature +0 -44
  60. data/features/config_project_name.feature +0 -27
  61. data/features/config_styles.feature +0 -121
  62. data/features/config_tracked_files.feature +0 -29
  63. data/features/config_tracked_files_relevant_lines.feature +0 -31
  64. data/features/cucumber_basic.feature +0 -29
  65. data/features/maximum_coverage_drop.feature +0 -89
  66. data/features/merging_test_unit_and_rspec.feature +0 -44
  67. data/features/minimum_coverage.feature +0 -59
  68. data/features/refuse_coverage_drop.feature +0 -95
  69. data/features/rspec_basic.feature +0 -32
  70. data/features/rspec_fails_on_initialization.feature +0 -14
  71. data/features/rspec_groups_and_filters_basic.feature +0 -29
  72. data/features/rspec_groups_and_filters_complex.feature +0 -37
  73. data/features/rspec_groups_using_filter_class.feature +0 -41
  74. data/features/rspec_without_simplecov.feature +0 -20
  75. data/features/skipping_code_blocks_manually.feature +0 -70
  76. data/features/step_definitions/html_steps.rb +0 -44
  77. data/features/step_definitions/simplecov_steps.rb +0 -68
  78. data/features/step_definitions/transformers.rb +0 -13
  79. data/features/step_definitions/web_steps.rb +0 -64
  80. data/features/support/aruba_freedom_patch.rb +0 -53
  81. data/features/support/env.rb +0 -50
  82. data/features/test_unit_basic.feature +0 -34
  83. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  84. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  85. data/features/test_unit_groups_using_filter_class.feature +0 -40
  86. data/features/test_unit_without_simplecov.feature +0 -20
  87. data/features/unicode_compatiblity.feature +0 -67
  88. data/lib/simplecov/jruby_fix.rb +0 -42
  89. data/lib/simplecov/railtie.rb +0 -7
  90. data/lib/simplecov/railties/tasks.rake +0 -11
  91. data/lib/simplecov/raw_coverage.rb +0 -39
  92. data/simplecov.gemspec +0 -27
  93. data/spec/1_8_fallbacks_spec.rb +0 -31
  94. data/spec/command_guesser_spec.rb +0 -48
  95. data/spec/config_loader_spec.rb +0 -14
  96. data/spec/configuration_spec.rb +0 -35
  97. data/spec/defaults_spec.rb +0 -41
  98. data/spec/deleted_source_spec.rb +0 -12
  99. data/spec/faked_project/Gemfile +0 -6
  100. data/spec/faked_project/Rakefile +0 -8
  101. data/spec/faked_project/cucumber.yml +0 -13
  102. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  103. data/spec/faked_project/features/support/env.rb +0 -12
  104. data/spec/faked_project/features/test_stuff.feature +0 -6
  105. data/spec/faked_project/lib/faked_project.rb +0 -11
  106. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  107. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  108. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  109. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  110. data/spec/faked_project/spec/faked_spec.rb +0 -11
  111. data/spec/faked_project/spec/forking_spec.rb +0 -8
  112. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  113. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  114. data/spec/faked_project/spec/spec_helper.rb +0 -11
  115. data/spec/faked_project/test/faked_test.rb +0 -11
  116. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  117. data/spec/faked_project/test/some_class_test.rb +0 -15
  118. data/spec/faked_project/test/test_helper.rb +0 -12
  119. data/spec/file_list_spec.rb +0 -50
  120. data/spec/filters_spec.rb +0 -202
  121. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  122. data/spec/fixtures/app/models/user.rb +0 -10
  123. data/spec/fixtures/deleted_source_sample.rb +0 -15
  124. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  125. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  126. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  127. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  128. data/spec/fixtures/iso-8859.rb +0 -3
  129. data/spec/fixtures/never.rb +0 -2
  130. data/spec/fixtures/resultset1.rb +0 -4
  131. data/spec/fixtures/resultset2.rb +0 -4
  132. data/spec/fixtures/sample.rb +0 -16
  133. data/spec/fixtures/skipped.rb +0 -4
  134. data/spec/fixtures/skipped_and_executed.rb +0 -8
  135. data/spec/fixtures/utf-8.rb +0 -3
  136. data/spec/helper.rb +0 -26
  137. data/spec/last_run_spec.rb +0 -48
  138. data/spec/lines_classifier_spec.rb +0 -103
  139. data/spec/multi_formatter_spec.rb +0 -20
  140. data/spec/raw_coverage_spec.rb +0 -92
  141. data/spec/result_merger_spec.rb +0 -171
  142. data/spec/result_spec.rb +0 -209
  143. data/spec/return_codes_spec.rb +0 -34
  144. data/spec/simplecov_spec.rb +0 -109
  145. data/spec/source_file_line_spec.rb +0 -155
  146. data/spec/source_file_spec.rb +0 -145
  147. data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8f001c1d4f9343c21eee5371b68f31a56caf35b752a08a662115418176a6156
4
- data.tar.gz: 519eaaee340436685bc0c31a61d9fc1356072e1d39d573bce8049afe79332252
3
+ metadata.gz: a5ac4654ad44859d2e7b68cc5375314766127720e33d51080cc02120d35cc9cb
4
+ data.tar.gz: 89ceeaf8b9b1a76bd05a4f078c50a80050bd247ef067164201f9721ce7378b5b
5
5
  SHA512:
6
- metadata.gz: 94a6c0d8f0245befdf662d339bae1b2e0d4a077d3591764f9c215f06453f9e86a40127d3fe5f7488875c470caf8743d19307352e72eaff6f5dfc2c657a828622
7
- data.tar.gz: eb674773b777504acba00508c7cc62f2e0f1451fb26d1a06463a822130e2cceeda4a8aba964569579becd62b7951f5968dbdd351549143cc81a69e1628923cad
6
+ metadata.gz: 8afee26e98b841b002d097d589afbbc8b892452897423c927b817b51696bb7063e3f2e849f462434b765fb09970fbb6759d31d5362ea5c6e90eb65e82824eb78
7
+ data.tar.gz: ed2f4ffab150fd1da883604eccec94a087184aeaadb4b4d6f1f7273efa6020d1034b9e2eebbc8b88a9c63c54d545ccd6db4f5db58ee29f8182703ed40281342e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,100 @@
1
+ 0.18.0.beta3 (2020-01-20)
2
+ ========================
3
+
4
+ ## Enhancements
5
+ * Instead of ignoring old `.resultset.json`s that are inside the merge timeout, adapt and respect them
6
+
7
+ ## Bugfixes
8
+ * Remove the constant warning printing if you still have a `.resultset.json` in pre 0.18 layout that is within your merge timeout
9
+
10
+ 0.18.0.beta2 (2020-01-19)
11
+ ===================
12
+
13
+ ## Enhancements
14
+ * only turn on the requested coverage criteria (when activating branch coverage before SimpleCov would also instruct Ruby to take Method coverage)
15
+ * Change how branch coverage is displayed, now it's `branch_type: hit_count` which should be more self explanatory. See [#830](https://github.com/colszowka/simplecov/pull/830) for an example and feel free to give feedback!
16
+ * Allow early running exit tasks and avoid the `at_exit` hook through the `SimpleCov.run_exit_tasks!` method. (thanks [@macumber](https://github.com/macumber))
17
+ * Allow manual collation of result sets through the `SimpleCov.collate` entrypoint. See the README for more details (thanks [@ticky](https://github.com/ticky))
18
+ * Within `case`, even if there is no `else` branch declared show missing coverage for it (aka no branch of it). See [#825](https://github.com/colszowka/simplecov/pull/825)
19
+ * Stop symbolizing all keys when loading cache (should lead to be faster and consume less memory)
20
+ * Cache whether we can use/are using branch coverage (should be slightly faster)
21
+
22
+ ## Bugfixes
23
+ * Fix a crash that happened when an old version of our internal cache file `.resultset.json` was still present
24
+
25
+ 0.18.0.beta1 (2020-01-05)
26
+ ===================
27
+
28
+ This is a huge release highlighted by changing our support for ruby versions to 2.4+ (so things that aren't EOL'ed) and finally adding branch coverage support!
29
+
30
+ This release is still beta because we'd love for you to test out branch coverage and get your feedback before doing a full release.
31
+
32
+ On a personal note from [@PragTob](https://github.com/PragTob/) thanks to [ruby together](https://rubytogether.org/) for sponsoring this work on SimpleCov making it possible to deliver this and subsequent releases.
33
+
34
+ ## Breaking
35
+ * Dropped support for all EOL'ed rubies meaning we only support 2.4+. Simplecov can no longer be installed on older rubies, but older simplecov releases should still work. (thanks [@deivid-rodriguez](https://github.com/deivid-rodriguez))
36
+ * Dropped the `rake simplecov` task that "magically" integreated with rails. It was always undocumented, caused some issues and [had some issues](https://github.com/colszowka/simplecov/issues/689#issuecomment-561572327). Use the integration as described in the README please :)
37
+
38
+ ## Enhancements
39
+
40
+ * Branch coverage is here! Please try it out and test it! You can activate it with `enable_coverage :branch`. See the README for more details. This is thanks to a bunch of people most notably [@som4ik](https://github.com/som4ik), [@tycooon](https://github.com/tycooon), [@stepozer](https://github.com/stepozer), [@klyonrad](https://github.com/klyonrad) and your humble maintainers also contributed ;)
41
+ * If the minimum coverage is set to be greater than 100, a warning will be shown. See [#737](https://github.com/colszowka/simplecov/pull/737) (thanks [@belfazt](https://github.com/belfazt))
42
+ * Add a configuration option to disable the printing of non-successful exit statuses. See [#747](https://github.com/colszowka/simplecov/pull/746) (thanks [@JacobEvelyn](https://github.com/JacobEvelyn))
43
+ * Calculating 100% coverage is now stricter, so 100% means 100%. See [#680](https://github.com/colszowka/simplecov/pull/680) thanks [@gleseur](https://github.com/gleseur)
44
+
45
+ ## Bugfixes
46
+
47
+ * Add new instance of `Minitest` constant. The `MiniTest` constant (with the capital T) will be removed in the next major release of Minitest. See [#757](https://github.com/colszowka/simplecov/pull/757) (thanks [@adam12](https://github.com/adam12))
48
+
49
+ 0.17.1 (2019-09-16)
50
+ ===================
51
+
52
+ Bugfix release for problems with ParallelTests.
53
+
54
+ ## Bugfixes
55
+
56
+ * Avoid hanging with parallel_tests. See [#746](https://github.com/colszowka/simplecov/pull/746) (thanks [@annaswims](https://github.com/annaswims))
57
+
58
+ 0.17.0 (2019-07-02)
59
+ ===================
60
+
61
+ Maintenance release with nice convenience features and important bugfixes.
62
+ Notably this **will be the last release to support ruby versions that have reached their end of life**. Moving forward official CRuby support will be 2.4+ and JRuby support will be 9.2+. Older versions might still work but no guarantees.
63
+
64
+ ## Enhancements
65
+
66
+ * Per default filter hidden files and folders. See [#721](https://github.com/colszowka/simplecov/pull/721) (thanks [Renuo AG](https://www.renuo.ch))
67
+ * Print the exit status explicitly when it's not a successful build so it's easier figure out SimpleCov failed the build in the output. See [#688](https://github.com/colszowka/simplecov/pull/688) (thanks [@daemonsy](https://github.com/daemonsy))
68
+
69
+ ## Bugfixes
70
+
71
+ * Avoid a premature failure exit code when setting `minimum_coverage` in combination with using [parallel_tests](https://github.com/grosser/parallel_tests). See [#706](https://github.com/colszowka/simplecov/pull/706) (thanks [@f1sherman](https://github.com/f1sherman))
72
+ * Project roots with special characters no longer cause crashes. See [#717](https://github.com/colszowka/simplecov/pull/717) (thanks [@deivid-rodriguez](https://github.com/deivid-rodriguez))
73
+ * Avoid continously overriding test results with manual `ResultMergere.store_results` usage. See [#674](https://github.com/colszowka/simplecov/pull/674) (thanks [@tomeon](https://github.com/tomeon))
74
+
75
+ 0.16.1 (2018-03-16)
76
+ ===================
77
+
78
+ ## Bugfixes
79
+
80
+ * Include the LICENSE in the distributed gem again (accidentally removed in 0.16.0). (thanks @tas50)
81
+
82
+ 0.16.0 (2018-03-15)
83
+ ===================
84
+
85
+ ## Enhancements
86
+
87
+ * Relax version constraint on `docile`, per SemVer
88
+ * exception that occurred on exit is available as `exit_exception`! See [#639](https://github.com/colszowka/simplecov/pull/639) (thanks @thomas07vt)
89
+ * Performance: processing results now runs from 2.5x to 3.75x faster. See [#662](https://github.com/colszowka/simplecov/pull/662) (thanks @BMorearty & @eregon)
90
+ * Decrease gem size by only shipping lib and docs
91
+
92
+ ## Bugfixes
93
+
94
+ * (breaking) Stop handling string filters as regular expressions, use the dedicated regex filter if you need that behaviour. See [#616](https://github.com/colszowka/simplecov/pull/616) (thanks @yujinakayama)
95
+ * Avoid overwriting the last coverage results on unsuccessful test runs. See [#625](https://github.com/colszowka/simplecov/pull/625) (thanks @thomas07vt)
96
+ * Don't crash on invalid UTF-8 byte sequences. (thanks @BMorearty)
97
+
1
98
  0.15.1 (2017-09-11) ([changes](https://github.com/colszowka/simplecov/compare/v0.15.0...v0.15.1))
2
99
  =======
3
100
 
@@ -16,7 +113,7 @@
16
113
  ## Bugfixes
17
114
 
18
115
  * Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng)
19
- * Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classigied as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp)
116
+ * Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classified as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp)
20
117
  * Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat)
21
118
  * Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
22
119
  * Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
@@ -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
@@ -2,19 +2,21 @@
2
2
 
3
3
  You can report issues at https://github.com/colszowka/simplecov/issues
4
4
 
5
- Search existing issues for your problem, chances are someone else already reported it.
5
+ Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
6
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)?
7
14
  * Include the SimpleCov version you are running in your report.
8
15
  * If you are not running the latest version (please check), and you cannot update it,
9
16
  please specify in your report why you can't update to the latest version.
10
17
  * Include your `ruby -e "puts RUBY_DESCRIPTION"`.
11
18
  * Please also specify the gem versions of Rails (if applicable).
12
19
  * Include any other coverage gems you may be using and their versions.
13
- * Include how you run your tests and which testing framework or frameworks you are running.
14
- - If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
15
- - Otherwise, please ensure you are requiring and starting SimpleCov before requiring any application code.
16
- For example, if running via RSpec, this would be at the top of your spec_helper.
17
- - Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)?
18
20
 
19
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.)
20
22
 
@@ -37,12 +39,13 @@ If you want to contribute, please:
37
39
  * Make your feature addition or bug fix.
38
40
  * Add tests for it. This is important so I don't break it in a future version unintentionally.
39
41
  * **Bonus Points** go out to anyone who also updates `CHANGELOG.md` :)
40
- * Send me a pull request on Github.
42
+ * Send me a pull request on GitHub.
41
43
 
42
44
  ## Running Individual Tests
43
45
 
44
- This project uses Test::Unit. Individual tests can be run like this:
46
+ This project uses RSpec and Cucumber. Individual tests can be run like this:
45
47
 
46
48
  ```bash
47
- ruby -I test path/to/test.rb
49
+ bundle exec rspec path/to/test.rb
50
+ bundle exec cucumber path/to/test.feature
48
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!
File without changes
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- SimpleCov [![Build Status](https://travis-ci.org/colszowka/simplecov.svg)][Continuous Integration] [![Dependency Status](https://gemnasium.com/colszowka/simplecov.svg)][Dependencies] [![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)
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
3
  **Code coverage for Ruby**
4
4
 
@@ -8,7 +8,7 @@ SimpleCov [![Build Status](https://travis-ci.org/colszowka/simplecov.svg)][Conti
8
8
  * [Rubygem]
9
9
  * [Continuous Integration]
10
10
 
11
- [Coverage]: http://www.ruby-doc.org/stdlib-2.1.0/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
11
+ [Coverage]: https://ruby-doc.org/stdlib/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
12
12
  [Source Code]: https://github.com/colszowka/simplecov "Source Code @ GitHub"
13
13
  [API documentation]: http://rubydoc.info/gems/simplecov/frames "RDoc API Documentation at Rubydoc.info"
14
14
  [Configuration]: http://rubydoc.info/gems/simplecov/SimpleCov/Configuration "Configuration options API documentation"
@@ -22,13 +22,14 @@ SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Co
22
22
  coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format,
23
23
  and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of
24
24
  code.
25
+ SimpleCov/Coverage track covered ruby code, gathering coverage for common templating solutions like erb, slim and haml is not supported.
25
26
 
26
27
  In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features,
27
28
  etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your
28
29
  report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
29
30
 
30
- The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and configured
31
- automatically when you launch SimpleCov. If you're curious, you can find it [on Github, too][simplecov-html].
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].
32
33
 
33
34
 
34
35
  ## Contact
@@ -36,21 +37,23 @@ automatically when you launch SimpleCov. If you're curious, you can find it [on
36
37
  *Code and Bug Reports*
37
38
 
38
39
  * [Issue Tracker](https://github.com/colszowka/simplecov/issues)
39
- * See [CONTRIBUTING](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md) for how to contribute along with some common problems to check out before creating an issue.
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.
40
42
 
41
43
  *Questions, Problems, Suggestions, etc.*
42
44
 
43
- * [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements on Google Groups"
45
+ * [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements
46
+ on Google Groups"
44
47
 
45
48
  Getting started
46
49
  ---------------
47
50
  1. Add SimpleCov to your `Gemfile` and `bundle install`:
48
51
 
49
52
  ```ruby
50
- gem 'simplecov', :require => false, :group => :test
53
+ gem 'simplecov', require: false, group: :test
51
54
  ```
52
55
  2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb`
53
- (*or `spec_helper.rb`, cucumber `env.rb`, or whatever your preferred test
56
+ (*or `spec_helper.rb`, `rails_helper`, cucumber `env.rb`, or whatever your preferred test
54
57
  framework uses*):
55
58
 
56
59
  ```ruby
@@ -70,8 +73,8 @@ Getting started
70
73
  endpoint) via a separate test process (e.g. when using Selenium) where you
71
74
  want to see all code executed by the `rails server`, and not just code
72
75
  executed in your actual test files, you'll want to add something like this
73
- to the top of `script/rails` (or `bin/rails` for Rails 4), but below the
74
- "shebang" line (`#! /usr/bin/env ruby`):
76
+ to the top of `bin/rails`, but below the "shebang" line (`#! /usr/bin/env
77
+ ruby`):
75
78
 
76
79
  ```ruby
77
80
  if ENV['RAILS_ENV'] == 'test'
@@ -81,23 +84,41 @@ Getting started
81
84
  end
82
85
  ```
83
86
 
84
- 3. Run your tests, open up `coverage/index.html` in your browser and check out
85
- what you've missed so far.
86
- 4. Add the following to your `.gitignore` file to ensure that coverage results
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
87
104
  are not tracked by Git (optional):
88
105
 
89
- ```
90
- coverage
91
- ```
106
+ ```
107
+ echo "coverage" >> .gitignore
108
+ ```
109
+ Or if you use Windows:
110
+ ```
111
+ echo coverage >> .gitignore
112
+ ```
92
113
 
93
- If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles)
94
- that will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of
95
- your test_helper should be like this:
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:
96
117
 
97
- ```ruby
98
- require 'simplecov'
99
- SimpleCov.start 'rails'
100
- ```
118
+ ```ruby
119
+ require 'simplecov'
120
+ SimpleCov.start 'rails'
121
+ ```
101
122
 
102
123
  ## Example output
103
124
 
@@ -123,8 +144,9 @@ require 'simplecov'
123
144
  SimpleCov.start 'rails'
124
145
  ```
125
146
 
126
- You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov does not
127
- care what kind of framework it is running in; it just looks at what code is being executed and generates a report about it.
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.
128
150
 
129
151
  ### Notes on specific frameworks and test utilities
130
152
 
@@ -135,28 +157,28 @@ to use SimpleCov with them. Here's an overview of the known ones:
135
157
  <tr><th>Framework</th><th>Notes</th><th>Issue</th></tr>
136
158
  <tr>
137
159
  <th>
138
- bootsnap
160
+ parallel_tests
139
161
  </th>
140
162
  <td>
141
- <a href="#want-to-use-bootsnap-with-simplecov">See section below.</a>
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.
142
167
  </td>
143
168
  <td>
144
- <a href="https://github.com/Shopify/bootsnap/issues/35">Shopify/bootsnap#35</a>
169
+ <a href="https://github.com/colszowka/simplecov/issues/64">#64</a> &amp;
170
+ <a href="https://github.com/colszowka/simplecov/pull/185">#185</a>
145
171
  </td>
146
172
  </tr>
147
173
  <tr>
148
174
  <th>
149
- parallel_tests
175
+ knapsack_pro
150
176
  </th>
151
177
  <td>
152
- As of 0.8.0, SimpleCov should correctly recognize parallel_tests and
153
- supplement your test suite names with their corresponding test env
154
- numbers. SimpleCov locks the resultset cache while merging, ensuring no
155
- race conditions occur when results are merged.
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.
156
179
  </td>
157
180
  <td>
158
- <a href="https://github.com/colszowka/simplecov/issues/64">#64</a> &amp;
159
- <a href="https://github.com/colszowka/simplecov/pull/185">#185</a>
181
+ <a href="https://knapsackpro.com/faq/question/how-to-use-simplecov-in-queue-mode">Tip</a>
160
182
  </td>
161
183
  </tr>
162
184
  <tr>
@@ -230,7 +252,8 @@ to use SimpleCov with them. Here's an overview of the known ones:
230
252
  ```ruby
231
253
  SimpleCov.some_config_option 'foo'
232
254
  ```
233
- * If you do not want to start coverage immediately after launch or want to add additional configuration later on in a concise way, use:
255
+ * If you do not want to start coverage immediately after launch or want to add additional configuration later on in a
256
+ concise way, use:
234
257
 
235
258
  ```ruby
236
259
  SimpleCov.configure do
@@ -242,11 +265,12 @@ Please check out the [Configuration] API documentation to find out what you can
242
265
 
243
266
  ## Using .simplecov for centralized config
244
267
 
245
- If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cucumber) into a single report, you'd normally have to
246
- set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
268
+ If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cucumber) into a single report, you'd
269
+ normally have to set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
247
270
 
248
- To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the `require 'simplecov'` in each
249
- test setup helper and move the `SimpleCov.start` code with all your custom config options into `.simplecov`:
271
+ To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the
272
+ `require 'simplecov'` in each test setup helper (**at the top**) and move the `SimpleCov.start` code with all your
273
+ custom config options into `.simplecov`:
250
274
 
251
275
  ```ruby
252
276
  # test/test_helper.rb
@@ -260,21 +284,74 @@ SimpleCov.start 'rails' do
260
284
  # any custom configs like groups and filters can be here at a central place
261
285
  end
262
286
  ```
263
- Using `.simplecov` rather than separately requiring SimpleCov multiple times is recommended if you are merging multiple test frameworks like Cucumber and RSpec that rely on each other, as invoking SimpleCov multiple times can cause coverage information to be lost.
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
+ # or in configure or just SimpleCov.enable_coverage :branch
297
+ SimpleCov.start do
298
+ enable_coverage :branch
299
+ end
300
+ ```
301
+
302
+ Branch coverage is a feature introduced in Ruby 2.5 concerning itself with whether a
303
+ particular branch of a condition had been executed. Line coverage on the other hand
304
+ is only interested in whether a line of code has been executed.
305
+
306
+ This comes in handy for instance for one line conditionals:
307
+
308
+ ```ruby
309
+ number.odd? ? "odd" : "even"
310
+ ```
311
+
312
+ In line coverage this line would always be marked as executed but you'd never know if both
313
+ conditions were met. Guard clauses have a similar story:
314
+
315
+ ```ruby
316
+ return if number.odd?
317
+
318
+ # more code
319
+ ```
320
+
321
+ If all the code in that method was covered you'd never know if the guard clause was ever
322
+ triggered! With line coverage as just evaluating the condition marks it as covered.
323
+
324
+ In the HTML report the lines of code will be annotated like `branch_type: hit_count`:
325
+
326
+ * `then: 2` - the then branch (of an `if`) was executed twice
327
+ * `else: 0` - the else branch (of an `if` or `case`) was never executed
328
+
329
+ Not that even if you don't declare an `else` branch it will still show up in the coverage
330
+ reports meaning that the condition of the `if` was not hit or that no `when` of `case`
331
+ was hit during the test runs.
332
+
333
+ **Is branch coverage strictly better?** No. Branch coverage really only concerns itself with
334
+ conditionals - meaning coverage of sequential code is of no interest to it. A file without
335
+ conditional logic will have no branch coverage data and SimpleCov will report 0 of 0
336
+ branches covered as 100% (as everything that can be covered was covered).
337
+
338
+ Hence, we recommend looking at both metrics together. Branch coverage might also be a good
339
+ overall metric to look at - while you might be missing only 10% of your lines that might
340
+ account for 50% of your branches for instance.
264
341
 
265
342
  ## Filters
266
343
 
267
- Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all files
268
- OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source files in the
269
- gems you are using.
344
+ Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
345
+ files OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source
346
+ files in the gems you are using.
270
347
 
271
348
  You can define your own to remove things like configuration files, tests or whatever you don't need in your coverage
272
349
  report.
273
350
 
274
351
  ### Defining custom filters
275
352
 
276
- You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source file's path),
277
- a block or by passing in your own Filter class.
353
+ You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source
354
+ file's path), a block or by passing in your own Filter class.
278
355
 
279
356
  #### String filter
280
357
 
@@ -306,9 +383,10 @@ SimpleCov.start do
306
383
  end
307
384
  ```
308
385
 
309
- Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be removed
310
- from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to learn about the
311
- methods available to you. In the above example, the filter will remove all files that have less than 5 lines of code.
386
+ Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be
387
+ removed from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to
388
+ learn about the methods available to you. In the above example, the filter will remove all files that have less than 5
389
+ lines of code.
312
390
 
313
391
  #### Custom filter class
314
392
 
@@ -322,9 +400,10 @@ end
322
400
  SimpleCov.add_filter LineFilter.new(5)
323
401
  ```
324
402
 
325
- Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method 'matches?(source_file)'. When running
326
- the filter, a true return value from this method will result in the removal of the given source_file. The filter_argument method
327
- is being set in the SimpleCov::Filter initialize method and thus is set to 5 in this example.
403
+ Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method
404
+ 'matches?(source_file)'. When running the filter, a true return value from this method will result in the removal of the
405
+ given source_file. The filter_argument method is being set in the SimpleCov::Filter initialize method and thus is set to
406
+ 5 in this example.
328
407
 
329
408
  #### Array filter
330
409
 
@@ -351,7 +430,9 @@ end
351
430
 
352
431
  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)
353
432
 
354
- **Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If you appropriately test the public interface of your classes and objects you should automatically get full coverage of your private methods.
433
+ **Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If
434
+ you appropriately test the public interface of your classes and objects you should automatically get full coverage of
435
+ your private methods.
355
436
 
356
437
  ## Default root filter and coverage for things outside of it
357
438
 
@@ -374,8 +455,8 @@ end
374
455
 
375
456
  You can separate your source files into groups. For example, in a Rails app, you'll want to have separate listings for
376
457
  Models, Controllers, Helpers, and Libs. Group definition works similarly to Filters (and also accepts custom
377
- filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering results,
378
- which exclude files from results when the filter results in a true value.
458
+ filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering
459
+ results, which exclude files from results when the filter results in a true value.
379
460
 
380
461
  Add your groups with:
381
462
 
@@ -395,12 +476,11 @@ end
395
476
 
396
477
  You normally want to have your coverage analyzed across ALL of your test suites, right?
397
478
 
398
- Simplecov automatically caches coverage results in your (coverage_path)/.resultset.json. Those results will then
399
- be automatically merged when generating the result, so when coverage is set up properly for Cucumber and your
400
- unit / functional / integration tests, all of those test suites will be taken into account when building the
401
- coverage report.
402
-
403
- There are two things to note here though:
479
+ Simplecov automatically caches coverage results in your
480
+ (coverage_path)/.resultset.json, and will merge or override those with
481
+ subsequent runs, depending on whether simplecov considers those subsequent runs
482
+ as different test suites or as the same test suite as the cached results. To
483
+ make this distinction, simplecov has the concept of "test suite names".
404
484
 
405
485
  ### Test suite names
406
486
 
@@ -454,24 +534,96 @@ SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '')
454
534
 
455
535
  [simplecov-html] prints the used test suites in the footer of the generated coverage report.
456
536
 
457
- ### Timeout for merge
458
537
 
459
- Of course, your cached coverage data is likely to become invalid at some point. Thus, result sets that are older than
460
- `SimpleCov.merge_timeout` will not be used any more. By default, the timeout is 600 seconds (10 minutes), and you can
461
- raise (or lower) it by specifying `SimpleCov.merge_timeout 3600` (1 hour), or, inside a configure/start block, with
462
- just `merge_timeout 3600`.
538
+ ### Merging test runs under the same execution environment
539
+
540
+ Test results are automatically merged with previous runs in the same execution
541
+ environment when generating the result, so when coverage is set up properly for
542
+ Cucumber and your unit / functional / integration tests, all of those test
543
+ suites will be taken into account when building the coverage report.
544
+
545
+ #### Timeout for merge
546
+
547
+ Of course, your cached coverage data is likely to become invalid at some point. Thus, when automatically merging
548
+ subsequent test runs, result sets that are older than `SimpleCov.merge_timeout` will not be used any more. By default,
549
+ the timeout is 600 seconds (10 minutes), and you can raise (or lower) it by specifying `SimpleCov.merge_timeout 3600`
550
+ (1 hour), or, inside a configure/start block, with just `merge_timeout 3600`.
551
+
552
+ You can deactivate this automatic merging altogether with `SimpleCov.use_merging false`.
553
+
554
+ ### Merging test runs under different execution environments
463
555
 
464
- You can deactivate merging altogether with `SimpleCov.use_merging false`.
556
+ If your tests are done in parallel across multiple build machines, you can fetch them all and merge them into a single
557
+ result set using the `SimpleCov.collate` method. This can be added to a Rakefile or script file, having downloaded a set of
558
+ `.resultset.json` files from each parallel test run.
559
+
560
+ ```ruby
561
+ # lib/tasks/coverage_report.rake
562
+ namespace :coverage do
563
+ desc "Collates all result sets generated by the different test runners"
564
+ task :report do
565
+ require 'simplecov'
566
+
567
+ SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"]
568
+ end
569
+ end
570
+ ```
571
+
572
+ `SimpleCov.collate` also takes an optional simplecov profile and an optional
573
+ block for configuration, just the same as `SimpleCov.start` or
574
+ `SimpleCov.configure`. This means you can configure a separate formatter for
575
+ the collated output. For instance, you can make the formatter in
576
+ `SimpleCov.start` the `SimpleCov::Formatter::SimpleFormatter`, and only use more
577
+ complex formatters in the final `SimpleCov.collate` run.
578
+
579
+ ```ruby
580
+ # spec/spec_helper.rb
581
+ require 'simplecov'
582
+
583
+ SimpleCov.start 'rails' do
584
+ # Disambiguates individual test runs
585
+ command_name "Job #{ENV["TEST_ENV_NUMBER"]}" if ENV["TEST_ENV_NUMBER"]
586
+
587
+ if ENV['CI']
588
+ formatter SimpleCov::Formatter::SimpleFormatter
589
+ else
590
+ formatter SimpleCov::Formatter::MultiFormatter.new([
591
+ SimpleCov::Formatter::SimpleFormatter,
592
+ SimpleCov::Formatter::HTMLFormatter
593
+ ])
594
+ end
595
+
596
+ track_files "**/*.rb"
597
+ end
598
+ ```
599
+
600
+ ```ruby
601
+ # lib/tasks/coverage_report.rake
602
+ namespace :coverage do
603
+ task :report do
604
+ require 'simplecov'
605
+
606
+ SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], 'rails' do
607
+ formatter SimpleCov::Formatter::MultiFormatter.new([
608
+ SimpleCov::Formatter::SimpleFormatter,
609
+ SimpleCov::Formatter::HTMLFormatter
610
+ ])
611
+ end
612
+ end
613
+ end
614
+ ```
465
615
 
466
616
  ## Running coverage only on demand
467
617
 
468
- The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed drop was
469
- only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you run your tests because
470
- it doesn't do your test speed any harm and you're always equipped with the latest and greatest coverage results.
618
+ The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed
619
+ drop was only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you
620
+ run your tests because it doesn't do your test speed any harm and you're always equipped with the latest and greatest
621
+ coverage results.
471
622
 
472
623
  Because of this, SimpleCov has no explicit built-in mechanism to run coverage only on demand.
473
624
 
474
- However, you can still accomplish this very easily by introducing an ENV variable conditional into your SimpleCov setup block, like this:
625
+ However, you can still accomplish this very easily by introducing an ENV variable conditional into your SimpleCov setup
626
+ block, like this:
475
627
 
476
628
  ```ruby
477
629
  SimpleCov.start if ENV["COVERAGE"]
@@ -483,6 +635,21 @@ Then, SimpleCov will only run if you execute your tests like this:
483
635
  COVERAGE=true rake test
484
636
  ```
485
637
 
638
+ ## Errors and exit statuses
639
+
640
+ To aid in debugging issues, if an error is raised, SimpleCov will print a message to `STDERR`
641
+ with the exit status of the error, like:
642
+
643
+ ```
644
+ SimpleCov failed with exit 1
645
+ ```
646
+
647
+ This `STDERR` message can be disabled with:
648
+
649
+ ```
650
+ SimpleCov.print_error_status = false
651
+ ```
652
+
486
653
  ## Profiles
487
654
 
488
655
  By default, SimpleCov's only config assumption is that you only want coverage reports for files inside your project
@@ -520,8 +687,8 @@ end
520
687
 
521
688
  ### Custom profiles
522
689
 
523
- You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an existing
524
- profile and customize it so you can reuse it in unit tests and Cucumber features. For example:
690
+ You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an
691
+ existing profile and customize it so you can reuse it in unit tests and Cucumber features. For example:
525
692
 
526
693
  ```ruby
527
694
  # lib/simplecov_custom_profile.rb
@@ -562,7 +729,8 @@ SimpleCov.minimum_coverage 90
562
729
 
563
730
  ### Minimum coverage by file
564
731
 
565
- You can define the minimum coverage by file percentage expected. SimpleCov will return non-zero if unmet. This is useful to help ensure coverage is relatively consistent, rather than being skewed by particularly good or bad areas of the code.
732
+ You can define the minimum coverage by file percentage expected. SimpleCov will return non-zero if unmet. This is useful
733
+ to help ensure coverage is relatively consistent, rather than being skewed by particularly good or bad areas of the code.
566
734
 
567
735
  ```ruby
568
736
  SimpleCov.minimum_coverage_by_file 80
@@ -592,8 +760,8 @@ You can use your own formatter with:
592
760
  SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
593
761
  ```
594
762
 
595
- When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result), "result"
596
- being an instance of SimpleCov::Result. Do whatever your wish with that!
763
+ When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result),
764
+ "result" being an instance of SimpleCov::Result. Do whatever your wish with that!
597
765
 
598
766
 
599
767
  ## Using multiple formatters
@@ -615,11 +783,9 @@ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
615
783
 
616
784
  ## Ruby version compatibility
617
785
 
618
- Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon and that's what SimpleCov supports. Additionally JRuby 9.1+ is supported as well, while JRuby 1.7 and 9.0 should work they're not "officially" supported.
619
- SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov
620
- does not make your test suite crash right now.
786
+ SimpleCov is built in [Continuous Integration] on Ruby 2.4+ as well as JRuby 9.2+.
621
787
 
622
- SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3, 2.4 as well as JRuby 9.1.
788
+ Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
623
789
 
624
790
  ## Want to find dead code in production?
625
791
 
@@ -627,49 +793,68 @@ Try [Coverband](https://github.com/danmayer/coverband).
627
793
 
628
794
  ## Want to use Spring with SimpleCov?
629
795
 
630
- If you're using [Spring](https://github.com/rails/spring) to speed up test suite runs and want to run SimpleCov along with them, you'll find that it often misreports coverage with the default config due to some sort of eager loading issue. Don't despair!
796
+ If you're using [Spring](https://github.com/rails/spring) to speed up test suite runs and want to run SimpleCov along
797
+ with them, you'll find that it often misreports coverage with the default config due to some sort of eager loading
798
+ issue. Don't despair!
631
799
 
632
- 1. Change the following settings in `test.rb`.
800
+ One solution is to [explicitly call eager
801
+ load](https://github.com/colszowka/simplecov/issues/381#issuecomment-347651728)
802
+ in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
633
803
 
634
- ```ruby
635
- # For Rails 4 or earlier, use the following configuration:
636
- # Disable Rails's static asset server (Apache or nginx will already do this)
637
- config.serve_static_files = false
638
- config.eager_load = false
639
-
640
- # For Rails 5, use the following configuration:
641
- # Disable Rails's static asset server (Apache or nginx will already do this)
642
- config.public_file_server.enabled = false
643
- config.eager_load = false
644
- ```
645
- 2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb`
646
- (or `rails_helper.rb` for RSpec 3). If you have a `config/spring.rb` file
647
- (or anything similar), add it to the start of such file. Here's a simple
648
- version of what the config should look like:
804
+ ```ruby
805
+ require 'simplecov'
806
+ SimpleCov.start 'rails'
807
+ Rails.application.eager_load!
808
+ ```
649
809
 
650
- ```ruby
651
- if ENV['RAILS_ENV'] == 'test'
652
- require 'simplecov'
653
- SimpleCov.start
654
- end
655
- ```
656
- 3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after
657
- making important changes to your app or its specs!
658
-
659
- ## Want to use bootsnap with SimpleCov?
810
+ Alternatively, you could disable Spring while running SimpleCov:
811
+
812
+ ```
813
+ DISABLE_SPRING=1 rake test
814
+ ```
815
+
816
+ Or you could remove `gem 'spring'` from your `Gemfile`.
817
+
818
+ ## Troubleshooting
660
819
 
661
- As mentioned in [this issue](https://github.com/Shopify/bootsnap/issues/35) iseq
662
- loading/dumping doesn't work with coverage. Hence you need to deactivate it when
663
- you run coverage so for instance when you use the environment `COVERAGE=true` to
664
- decide that you want to gather coverage you can do:
820
+ The **most common problem is that simplecov isn't required and started before everything else**. In order to track
821
+ coverage for your whole application **simplecov needs to be the first one** so that it (and the underlying coverage
822
+ library) can subsequently track loaded files and their usage.
823
+
824
+ If you are missing coverage for some code a simple trick is to put a puts statement in there and right after
825
+ `SimpleCov.start` so you can see if the file really was loaded after simplecov was started.
665
826
 
666
827
  ```ruby
667
- Bootsnap.setup(
668
- compile_cache_iseq: !ENV["COVERAGE"], # Compile Ruby code into ISeq cache, breaks coverage reporting.
669
- # all those other options
670
- )
828
+ # my_code.rb
829
+ class MyCode
830
+
831
+ puts "MyCode is being loaded!"
832
+
833
+ def my_method
834
+ # ...
835
+ end
836
+ end
837
+
838
+ # spec_helper.rb/rails_helper.rb/test_helper.rb/.simplecov whatever
839
+
840
+ SimpleCov.start
841
+ puts "SimpleCov started successfully!"
671
842
  ```
672
843
 
844
+ Now when you run your test suite and you see:
845
+
846
+ ```
847
+ SimpleCov started successfully!
848
+ MyCode is being loaded!
849
+ ```
850
+
851
+ then it's good otherwise you likely have a problem :)
852
+
853
+ ## Code of Conduct
854
+
855
+ Everyone participating in this project's development, issue trackers and other channels is expected to follow our
856
+ [Code of Conduct](./CODE_OF_CONDUCT.md)
857
+
673
858
  ## Contributing
674
859
 
675
860
  See the [contributing guide](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md).