simplecov 0.15.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -2
  3. data/CONTRIBUTING.md +12 -9
  4. data/ISSUE_TEMPLATE.md +23 -0
  5. data/{MIT-LICENSE → LICENSE} +0 -0
  6. data/README.md +50 -54
  7. data/doc/alternate-formatters.md +21 -1
  8. data/lib/simplecov.rb +112 -0
  9. data/lib/simplecov/command_guesser.rb +2 -0
  10. data/lib/simplecov/configuration.rb +2 -0
  11. data/lib/simplecov/defaults.rb +11 -80
  12. data/lib/simplecov/exit_codes.rb +2 -0
  13. data/lib/simplecov/file_list.rb +2 -0
  14. data/lib/simplecov/filter.rb +3 -1
  15. data/lib/simplecov/formatter.rb +2 -0
  16. data/lib/simplecov/formatter/multi_formatter.rb +2 -0
  17. data/lib/simplecov/formatter/simple_formatter.rb +2 -0
  18. data/lib/simplecov/jruby_fix.rb +2 -0
  19. data/lib/simplecov/last_run.rb +2 -0
  20. data/lib/simplecov/lines_classifier.rb +19 -3
  21. data/lib/simplecov/load_global_config.rb +2 -0
  22. data/lib/simplecov/no_defaults.rb +2 -0
  23. data/lib/simplecov/profiles.rb +2 -0
  24. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  25. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  26. data/lib/simplecov/profiles/rails.rb +18 -0
  27. data/lib/simplecov/profiles/root_filter.rb +10 -0
  28. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  29. data/lib/simplecov/railtie.rb +2 -0
  30. data/lib/simplecov/railties/tasks.rake +2 -0
  31. data/lib/simplecov/raw_coverage.rb +2 -0
  32. data/lib/simplecov/result.rb +2 -0
  33. data/lib/simplecov/result_merger.rb +2 -0
  34. data/lib/simplecov/source_file.rb +4 -2
  35. data/lib/simplecov/version.rb +3 -1
  36. metadata +138 -120
  37. data/.gitignore +0 -31
  38. data/.rspec +0 -3
  39. data/.rubocop.yml +0 -88
  40. data/.travis.yml +0 -29
  41. data/.yardopts +0 -1
  42. data/Gemfile +0 -38
  43. data/Rakefile +0 -41
  44. data/cucumber.yml +0 -13
  45. data/features/config_autoload.feature +0 -46
  46. data/features/config_command_name.feature +0 -45
  47. data/features/config_coverage_dir.feature +0 -33
  48. data/features/config_deactivate_merging.feature +0 -42
  49. data/features/config_formatters.feature +0 -77
  50. data/features/config_merge_timeout.feature +0 -39
  51. data/features/config_nocov_token.feature +0 -79
  52. data/features/config_profiles.feature +0 -44
  53. data/features/config_project_name.feature +0 -27
  54. data/features/config_styles.feature +0 -121
  55. data/features/config_tracked_files.feature +0 -29
  56. data/features/config_tracked_files_relevant_lines.feature +0 -31
  57. data/features/cucumber_basic.feature +0 -29
  58. data/features/maximum_coverage_drop.feature +0 -89
  59. data/features/merging_test_unit_and_rspec.feature +0 -44
  60. data/features/minimum_coverage.feature +0 -59
  61. data/features/refuse_coverage_drop.feature +0 -95
  62. data/features/rspec_basic.feature +0 -32
  63. data/features/rspec_fails_on_initialization.feature +0 -14
  64. data/features/rspec_groups_and_filters_basic.feature +0 -29
  65. data/features/rspec_groups_and_filters_complex.feature +0 -37
  66. data/features/rspec_groups_using_filter_class.feature +0 -41
  67. data/features/rspec_without_simplecov.feature +0 -20
  68. data/features/skipping_code_blocks_manually.feature +0 -70
  69. data/features/step_definitions/html_steps.rb +0 -44
  70. data/features/step_definitions/simplecov_steps.rb +0 -68
  71. data/features/step_definitions/transformers.rb +0 -13
  72. data/features/step_definitions/web_steps.rb +0 -64
  73. data/features/support/aruba_freedom_patch.rb +0 -53
  74. data/features/support/env.rb +0 -50
  75. data/features/test_unit_basic.feature +0 -34
  76. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  77. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  78. data/features/test_unit_groups_using_filter_class.feature +0 -40
  79. data/features/test_unit_without_simplecov.feature +0 -20
  80. data/features/unicode_compatiblity.feature +0 -67
  81. data/simplecov.gemspec +0 -27
  82. data/spec/1_8_fallbacks_spec.rb +0 -31
  83. data/spec/command_guesser_spec.rb +0 -48
  84. data/spec/config_loader_spec.rb +0 -14
  85. data/spec/configuration_spec.rb +0 -35
  86. data/spec/deleted_source_spec.rb +0 -12
  87. data/spec/faked_project/Gemfile +0 -6
  88. data/spec/faked_project/Rakefile +0 -8
  89. data/spec/faked_project/cucumber.yml +0 -13
  90. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  91. data/spec/faked_project/features/support/env.rb +0 -12
  92. data/spec/faked_project/features/test_stuff.feature +0 -6
  93. data/spec/faked_project/lib/faked_project.rb +0 -11
  94. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  95. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  96. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  97. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  98. data/spec/faked_project/spec/faked_spec.rb +0 -11
  99. data/spec/faked_project/spec/forking_spec.rb +0 -8
  100. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  101. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  102. data/spec/faked_project/spec/spec_helper.rb +0 -11
  103. data/spec/faked_project/test/faked_test.rb +0 -11
  104. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  105. data/spec/faked_project/test/some_class_test.rb +0 -15
  106. data/spec/faked_project/test/test_helper.rb +0 -12
  107. data/spec/file_list_spec.rb +0 -50
  108. data/spec/filters_spec.rb +0 -172
  109. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  110. data/spec/fixtures/app/models/user.rb +0 -10
  111. data/spec/fixtures/deleted_source_sample.rb +0 -15
  112. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  113. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  114. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  115. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  116. data/spec/fixtures/iso-8859.rb +0 -3
  117. data/spec/fixtures/never.rb +0 -2
  118. data/spec/fixtures/resultset1.rb +0 -4
  119. data/spec/fixtures/resultset2.rb +0 -4
  120. data/spec/fixtures/sample.rb +0 -16
  121. data/spec/fixtures/skipped.rb +0 -4
  122. data/spec/fixtures/skipped_and_executed.rb +0 -8
  123. data/spec/fixtures/utf-8.rb +0 -3
  124. data/spec/helper.rb +0 -26
  125. data/spec/last_run_spec.rb +0 -48
  126. data/spec/lines_classifier_spec.rb +0 -103
  127. data/spec/multi_formatter_spec.rb +0 -20
  128. data/spec/raw_coverage_spec.rb +0 -92
  129. data/spec/result_merger_spec.rb +0 -171
  130. data/spec/result_spec.rb +0 -209
  131. data/spec/return_codes_spec.rb +0 -34
  132. data/spec/simplecov_spec.rb +0 -109
  133. data/spec/source_file_line_spec.rb +0 -155
  134. data/spec/source_file_spec.rb +0 -145
  135. 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: 316080f1732d39e050a8c0310aa1527717c2216ac5ab7b570dca4076e358a041
4
- data.tar.gz: 1417f8a0e41fab72d8b2d86b583dec9c5b47adde77f26dce84ee3646985b0a43
3
+ metadata.gz: 6f3e7730302a3a31266a22a830aa6a098e17cc4042f664e4f9a079eef408897f
4
+ data.tar.gz: 423ed5a50493415c4c8bb17ff9c82ffd84e75dc98fc14cc0b4e82f17491d483e
5
5
  SHA512:
6
- metadata.gz: 3d58eee98ca6d7da2412747c6972560cdb835f110d37041a84816d44b8d433deb9d2b0bf20ce29012f90d2f2978afed2ae1bfdde3540b4d078a69adb2a64623e
7
- data.tar.gz: cbbf89810a47ffec5328846f0135e98fac7fc0827d5cda4db59c8b761ce7c307e73f8cdc4e15e8db8e192e28b5c0eed8c15399f52bedacca4517cc76ef0556e5
6
+ metadata.gz: 5b46e9d714b0a675de3b2e42284069942479af4fb0df627b3806fb48e8d373ea7f555fc8cf482682e15e8a6e335ea82358e4b4db28b1257183ae22d018c17f21
7
+ data.tar.gz: 82eedda10bb5786656190ec0ca7dd1a3e18c38f6526db25f90c9b614849e05a14b85a34257343c5f48f62cffc7ddbdb74505b896a7c72236992aadd83c945a24
data/CHANGELOG.md CHANGED
@@ -1,3 +1,60 @@
1
+ 0.17.1 (2019-09-16)
2
+ ===================
3
+
4
+ Bugfix release for problems with ParallelTests.
5
+
6
+ ## Bugfixes
7
+
8
+ * Avoid hanging with parallel_tests. See [#746](https://github.com/colszowka/simplecov/pull/746) (thanks [@annaswims](https://github.com/annaswims))
9
+
10
+ 0.17.0 (2019-07-02)
11
+ ===================
12
+
13
+ Maintenance release with nice convenience features and important bugfixes.
14
+ 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.1+. Older versions might still work but no guarantees.
15
+
16
+ ## Enhancements
17
+
18
+ * Per default filter hidden files and folders. See [#721](https://github.com/colszowka/simplecov/pull/721) (thanks [Renuo AG](https://www.renuo.ch))
19
+ * 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))
20
+
21
+ ## Bugfixes
22
+
23
+ * 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))
24
+ * 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))
25
+ * 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))
26
+
27
+ 0.16.1 (2018-03-16)
28
+ ===================
29
+
30
+ ## Bugfixes
31
+
32
+ * Include the LICENSE in the distributed gem again (accidentally removed in 0.16.0). (thanks @tas50)
33
+
34
+ 0.16.0 (2018-03-15)
35
+ ===================
36
+
37
+ ## Enhancements
38
+
39
+ * Relax version constraint on `docile`, per SemVer
40
+ * exception that occurred on exit is available as `exit_exception`! See [#639](https://github.com/colszowka/simplecov/pull/639) (thanks @thomas07vt)
41
+ * Performance: processing results now runs from 2.5x to 3.75x faster. See [#662](https://github.com/colszowka/simplecov/pull/662) (thanks @BMorearty & @eregon)
42
+ * Decrease gem size by only shipping lib and docs
43
+
44
+ ## Bugfixes
45
+
46
+ * (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)
47
+ * Avoid overwriting the last coverage results on unsuccessful test runs. See [#625](https://github.com/colszowka/simplecov/pull/625) (thanks @thomas07vt)
48
+ * Don't crash on invalid UTF-8 byte sequences. (thanks @BMorearty)
49
+
50
+ 0.15.1 (2017-09-11) ([changes](https://github.com/colszowka/simplecov/compare/v0.15.0...v0.15.1))
51
+ =======
52
+
53
+ ## Bugfixes
54
+
55
+ * Filter directories outside SimpleCov.root that have it as a prefix. See [#617](https://github.com/colszowka/simplecov/pull/617) (thanks @jenseng)
56
+ * Fix standard rails profile rails filter (didn't work). See [#618](https://github.com/colszowka/simplecov/pull/618) (thanks @jenseng again!)
57
+
1
58
  0.15.0 (2017-08-14) ([changes](https://github.com/colszowka/simplecov/compare/v0.14.1...v0.15.0))
2
59
  =======
3
60
 
@@ -8,7 +65,7 @@
8
65
  ## Bugfixes
9
66
 
10
67
  * Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng)
11
- * 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)
68
+ * 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)
12
69
  * Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat)
13
70
  * Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
14
71
  * 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)
@@ -271,7 +328,7 @@ has been added.
271
328
  * Average hits per line for groups of files is now computed correctly.
272
329
  See [#192](http://github.com/colszowka/simplecov/pull/192) and
273
330
  [#179](http://github.com/colszowka/simplecov/issues/179) (thanks to @graysonwright)
274
- * Compatability with BINARY internal encoding.
331
+ * Compatibility with BINARY internal encoding.
275
332
  See [#194](https://github.com/colszowka/simplecov/pull/194) and
276
333
  [#127](https://github.com/colszowka/simplecov/issues/127) (thanks to @justfalter)
277
334
  * Special characters in `SimpleCov.root` are now correctly escaped before being used as a RegExp.
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 [![Build Status](https://travis-ci.org/colszowka/simplecov.svg)][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
 
@@ -28,7 +28,7 @@ etc. SimpleCov automatically takes care of this by caching and merging results w
28
28
  report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
29
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
+ automatically when you launch SimpleCov. If you're curious, you can find it [on GitHub, too][simplecov-html].
32
32
 
33
33
 
34
34
  ## Contact
@@ -47,10 +47,10 @@ Getting started
47
47
  1. Add SimpleCov to your `Gemfile` and `bundle install`:
48
48
 
49
49
  ```ruby
50
- gem 'simplecov', :require => false, :group => :test
50
+ gem 'simplecov', require: false, group: :test
51
51
  ```
52
52
  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
53
+ (*or `spec_helper.rb`, `rails_helper`, cucumber `env.rb`, or whatever your preferred test
54
54
  framework uses*):
55
55
 
56
56
  ```ruby
@@ -87,7 +87,11 @@ Getting started
87
87
  are not tracked by Git (optional):
88
88
 
89
89
  ```
90
- coverage
90
+ echo "coverage" >> .gitignore
91
+ ```
92
+ Or if you use Windows:
93
+ ```
94
+ echo coverage >> .gitignore
91
95
  ```
92
96
 
93
97
  If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles)
@@ -133,17 +137,6 @@ to use SimpleCov with them. Here's an overview of the known ones:
133
137
 
134
138
  <table>
135
139
  <tr><th>Framework</th><th>Notes</th><th>Issue</th></tr>
136
- <tr>
137
- <th>
138
- bootsnap
139
- </th>
140
- <td>
141
- <a href="#want-to-use-bootsnap-with-simplecov">See section below.</a>
142
- </td>
143
- <td>
144
- <a href="https://github.com/Shopify/bootsnap/issues/35">Shopify/bootsnap#35</a>
145
- </td>
146
- </tr>
147
140
  <tr>
148
141
  <th>
149
142
  parallel_tests
@@ -246,7 +239,7 @@ If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cu
246
239
  set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
247
240
 
248
241
  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`:
242
+ test setup helper (**at the top**) and move the `SimpleCov.start` code with all your custom config options into `.simplecov`:
250
243
 
251
244
  ```ruby
252
245
  # test/test_helper.rb
@@ -260,6 +253,7 @@ SimpleCov.start 'rails' do
260
253
  # any custom configs like groups and filters can be here at a central place
261
254
  end
262
255
  ```
256
+
263
257
  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.
264
258
 
265
259
  ## Filters
@@ -349,8 +343,7 @@ end
349
343
  # :nocov:
350
344
  ```
351
345
 
352
- The name of the token can be changed to your liking. [Learn more about the nocov feature.][nocov]
353
- [nocov]: https://github.com/colszowka/simplecov/blob/master/features/config_nocov_token.feature
346
+ 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)
354
347
 
355
348
  **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.
356
349
 
@@ -620,7 +613,7 @@ Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon and t
620
613
  SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov
621
614
  does not make your test suite crash right now.
622
615
 
623
- 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.
616
+ SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3, 2.4, 2.5 as well as JRuby 9.1.
624
617
 
625
618
  ## Want to find dead code in production?
626
619
 
@@ -630,46 +623,49 @@ Try [Coverband](https://github.com/danmayer/coverband).
630
623
 
631
624
  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!
632
625
 
633
- 1. Change the following settings in `test.rb`.
626
+ One solution is to [explicitly call eager
627
+ load](https://github.com/colszowka/simplecov/issues/381#issuecomment-347651728)
628
+ in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
634
629
 
635
- ```ruby
636
- # For Rails 4 or earlier, use the following configuration:
637
- # Disable Rails's static asset server (Apache or nginx will already do this)
638
- config.serve_static_files = false
639
- config.eager_load = false
640
-
641
- # For Rails 5, use the following configuration:
642
- # Disable Rails's static asset server (Apache or nginx will already do this)
643
- config.public_file_server.enabled = false
644
- config.eager_load = false
645
- ```
646
- 2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb`
647
- (or `rails_helper.rb` for RSpec 3). If you have a `config/spring.rb` file
648
- (or anything similar), add it to the start of such file. Here's a simple
649
- version of what the config should look like:
630
+ ```ruby
631
+ require 'simplecov'
632
+ SimpleCov.start 'rails'
633
+ Rails.application.eager_load!
634
+ ```
650
635
 
651
- ```ruby
652
- if ENV['RAILS_ENV'] == 'test'
653
- require 'simplecov'
654
- SimpleCov.start
655
- end
656
- ```
657
- 3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after
658
- making important changes to your app or its specs!
659
-
660
- ## Want to use bootsnap with SimpleCov?
636
+ Or you could remove `gem 'spring'` from your `Gemfile`.
637
+
638
+ ## Troubleshooting
661
639
 
662
- As mentioned in [this issue](https://github.com/Shopify/bootsnap/issues/35) iseq
663
- loading/dumping doesn't work with coverage. Hence you need to deactivate it when
664
- you run coverage so for instance when you use the environment `COVERAGE=true` to
665
- decide that you want to gather coverage you can do:
640
+ The **most common problem is that simplecov isn't required and started before everything else**. In order to track coverage for your whole application **simplecov needs to be the first one** so that it (and the underlying coverage library) can subsequently track loaded files and their usage.
641
+
642
+ If you are missing coverage for some code a simple trick is to put a puts statement in there and right after `SimpleCov.start` so you can see if the file really was loaded after simplecov was started.
666
643
 
667
644
  ```ruby
668
- Bootsnap.setup(
669
- compile_cache_iseq: !ENV["COVERAGE"], # Compile Ruby code into ISeq cache, breaks coverage reporting.
670
- # all those other options
671
- )
645
+ # my_code.rb
646
+ class MyCode
647
+
648
+ puts "MyCode is being loaded!"
649
+
650
+ def my_method
651
+ # ...
652
+ end
653
+ end
654
+
655
+ # spec_helper.rb/rails_helper.rb/test_helper.rb/.simplecov whatever
656
+
657
+ SimpleCov.start
658
+ puts "SimpleCov started successfully!"
659
+ ```
660
+
661
+ Now when you run your test suite and you see:
662
+
672
663
  ```
664
+ SimpleCov started successfully!
665
+ MyCode is being loaded!
666
+ ```
667
+
668
+ then it's good otherwise you likely have a problem :)
673
669
 
674
670
  ## Contributing
675
671
 
@@ -10,6 +10,11 @@ If you have built or found one that is missing here, please send a Pull Request
10
10
 
11
11
  A formatter that generates a coverage badge for use in your project's readme using ImageMagick.
12
12
 
13
+ #### [simplecov-small-badge](https://github.com/marcgrimme/simplecov-small-badge)
14
+ *by Marc Grimme*
15
+
16
+ A formatter that generates a small coverage badge for use in your project's readme using the SVG.
17
+
13
18
  #### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura)
14
19
  *by Jesse Bowes*
15
20
 
@@ -20,11 +25,21 @@ A formatter that generates Cobertura XML.
20
25
 
21
26
  CSV formatter for SimpleCov
22
27
 
28
+ #### [simplecov-erb](https://github.com/kpaulisse/simplecov-erb)
29
+ *by [Kevin Paulisse](https://github.com/kpaulisse)*
30
+
31
+ Flexible formatter that generates the output from an ERB template.
32
+
23
33
  #### [simplecov-json](https://github.com/vicentllongo/simplecov-json)
24
34
  *by Vicent Llongo*
25
35
 
26
36
  JSON formatter for SimpleCov
27
37
 
38
+ #### [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov)
39
+ *by fortissimo1997*
40
+
41
+ lcov formatter for SimpleCov
42
+
28
43
  #### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov)
29
44
  *by Fernando Guillen*
30
45
 
@@ -33,4 +48,9 @@ JSON formatter for SimpleCov
33
48
  #### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter)
34
49
  *by [Michael Grosser](http://grosser.it)*
35
50
 
36
- A formatter that prints the coverage of the file under test when you run a single test file.
51
+ A formatter that prints the coverage of the file under test when you run a single test file.
52
+
53
+ #### [simplecov-t_wada](https://github.com/ysksn/simplecov-t_wada)
54
+ *by [Yosuke Kabuto](https://github.com/ysksn)*
55
+
56
+ t_wada AA formatter for SimpleCov
data/lib/simplecov.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+
1
5
  #
2
6
  # Code coverage for ruby 1.9. Please check out README for a full introduction.
3
7
  #
@@ -20,6 +24,7 @@ module SimpleCov
20
24
  class << self
21
25
  attr_accessor :running
22
26
  attr_accessor :pid
27
+ attr_reader :exit_exception
23
28
 
24
29
  #
25
30
  # Sets up SimpleCov to run against your project.
@@ -85,6 +90,7 @@ module SimpleCov
85
90
  # If we're using merging of results, store the current result
86
91
  # first (if there is one), then merge the results and return those
87
92
  if use_merging
93
+ wait_for_other_processes
88
94
  SimpleCov::ResultMerger.store_result(@result) if result?
89
95
  @result = SimpleCov::ResultMerger.merged_result
90
96
  end
@@ -163,6 +169,112 @@ module SimpleCov
163
169
  def clear_result
164
170
  @result = nil
165
171
  end
172
+
173
+ #
174
+ # Capture the current exception if it exists
175
+ # This will get called inside the at_exit block
176
+ #
177
+ def set_exit_exception
178
+ @exit_exception = $ERROR_INFO
179
+ end
180
+
181
+ #
182
+ # Returns the exit status from the exit exception
183
+ #
184
+ def exit_status_from_exception
185
+ return SimpleCov::ExitCodes::SUCCESS unless exit_exception
186
+
187
+ if exit_exception.is_a?(SystemExit)
188
+ exit_exception.status
189
+ else
190
+ SimpleCov::ExitCodes::EXCEPTION
191
+ end
192
+ end
193
+
194
+ # @api private
195
+ #
196
+ # Called from at_exit block
197
+ #
198
+ def run_exit_tasks!
199
+ exit_status = SimpleCov.exit_status_from_exception
200
+
201
+ SimpleCov.at_exit.call
202
+
203
+ # Don't modify the exit status unless the result has already been
204
+ # computed
205
+ exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) if SimpleCov.result?
206
+
207
+ # Force exit with stored status (see github issue #5)
208
+ # unless it's nil or 0 (see github issue #281)
209
+ if exit_status && exit_status > 0
210
+ $stderr.printf("SimpleCov failed with exit %d", exit_status)
211
+ Kernel.exit exit_status
212
+ end
213
+ end
214
+
215
+ # @api private
216
+ #
217
+ # Usage:
218
+ # exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
219
+ #
220
+ def process_result(result, exit_status)
221
+ return exit_status if exit_status != SimpleCov::ExitCodes::SUCCESS # Existing errors
222
+
223
+ covered_percent = result.covered_percent.round(2)
224
+ result_exit_status = result_exit_status(result, covered_percent)
225
+ if result_exit_status == SimpleCov::ExitCodes::SUCCESS # No result errors
226
+ write_last_run(covered_percent)
227
+ end
228
+ final_result_process? ? result_exit_status : SimpleCov::ExitCodes::SUCCESS
229
+ end
230
+
231
+ # @api private
232
+ #
233
+ # rubocop:disable Metrics/MethodLength
234
+ def result_exit_status(result, covered_percent)
235
+ covered_percentages = result.covered_percentages.map { |percentage| percentage.round(2) }
236
+ if covered_percent < SimpleCov.minimum_coverage
237
+ $stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
238
+ SimpleCov::ExitCodes::MINIMUM_COVERAGE
239
+ elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file }
240
+ $stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
241
+ SimpleCov::ExitCodes::MINIMUM_COVERAGE
242
+ elsif (last_run = SimpleCov::LastRun.read)
243
+ coverage_diff = last_run["result"]["covered_percent"] - covered_percent
244
+ if coverage_diff > SimpleCov.maximum_coverage_drop
245
+ $stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
246
+ SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
247
+ else
248
+ SimpleCov::ExitCodes::SUCCESS
249
+ end
250
+ else
251
+ SimpleCov::ExitCodes::SUCCESS
252
+ end
253
+ end
254
+ # rubocop:enable Metrics/MethodLength
255
+
256
+ #
257
+ # @api private
258
+ #
259
+ def final_result_process?
260
+ # checking for ENV["TEST_ENV_NUMBER"] to determine if the tess are being run in parallel
261
+ !defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests.number_of_running_processes <= 1
262
+ end
263
+
264
+ #
265
+ # @api private
266
+ #
267
+ def wait_for_other_processes
268
+ return unless defined?(ParallelTests) && final_result_process?
269
+ ParallelTests.wait_for_other_processes_to_finish
270
+ end
271
+
272
+ #
273
+ # @api private
274
+ #
275
+ def write_last_run(covered_percent)
276
+ SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
277
+ end
166
278
  end
167
279
  end
168
280