simplecov 0.13.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +99 -3
  3. data/CONTRIBUTING.md +12 -9
  4. data/ISSUE_TEMPLATE.md +23 -0
  5. data/{MIT-LICENSE → LICENSE} +1 -1
  6. data/README.md +90 -43
  7. data/doc/alternate-formatters.md +21 -1
  8. data/doc/editor-integration.md +6 -1
  9. data/lib/simplecov.rb +131 -13
  10. data/lib/simplecov/command_guesser.rb +2 -0
  11. data/lib/simplecov/configuration.rb +34 -25
  12. data/lib/simplecov/defaults.rb +12 -82
  13. data/lib/simplecov/exit_codes.rb +2 -0
  14. data/lib/simplecov/file_list.rb +7 -5
  15. data/lib/simplecov/filter.rb +41 -4
  16. data/lib/simplecov/formatter.rb +2 -0
  17. data/lib/simplecov/formatter/multi_formatter.rb +2 -0
  18. data/lib/simplecov/formatter/simple_formatter.rb +3 -1
  19. data/lib/simplecov/jruby_fix.rb +2 -0
  20. data/lib/simplecov/last_run.rb +5 -1
  21. data/lib/simplecov/lines_classifier.rb +48 -0
  22. data/lib/simplecov/load_global_config.rb +8 -0
  23. data/lib/simplecov/no_defaults.rb +2 -0
  24. data/lib/simplecov/profiles.rb +2 -0
  25. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  26. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  27. data/lib/simplecov/profiles/rails.rb +18 -0
  28. data/lib/simplecov/profiles/root_filter.rb +10 -0
  29. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  30. data/lib/simplecov/railtie.rb +2 -0
  31. data/lib/simplecov/railties/tasks.rake +2 -0
  32. data/lib/simplecov/raw_coverage.rb +41 -0
  33. data/lib/simplecov/result.rb +2 -1
  34. data/lib/simplecov/result_merger.rb +56 -21
  35. data/lib/simplecov/source_file.rb +43 -34
  36. data/lib/simplecov/version.rb +3 -23
  37. metadata +131 -99
  38. data/.gitignore +0 -31
  39. data/.rspec +0 -3
  40. data/.rubocop.yml +0 -84
  41. data/.travis.yml +0 -32
  42. data/.yardopts +0 -1
  43. data/Gemfile +0 -38
  44. data/Rakefile +0 -41
  45. data/cucumber.yml +0 -13
  46. data/features/config_autoload.feature +0 -46
  47. data/features/config_command_name.feature +0 -45
  48. data/features/config_coverage_dir.feature +0 -33
  49. data/features/config_deactivate_merging.feature +0 -42
  50. data/features/config_formatters.feature +0 -77
  51. data/features/config_merge_timeout.feature +0 -39
  52. data/features/config_nocov_token.feature +0 -79
  53. data/features/config_profiles.feature +0 -44
  54. data/features/config_project_name.feature +0 -27
  55. data/features/config_styles.feature +0 -121
  56. data/features/config_tracked_files.feature +0 -29
  57. data/features/cucumber_basic.feature +0 -29
  58. data/features/maximum_coverage_drop.feature +0 -36
  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 -35
  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/env.rb +0 -50
  74. data/features/test_unit_basic.feature +0 -34
  75. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  76. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  77. data/features/test_unit_groups_using_filter_class.feature +0 -40
  78. data/features/test_unit_without_simplecov.feature +0 -20
  79. data/features/unicode_compatiblity.feature +0 -67
  80. data/lib/simplecov/merge_helpers.rb +0 -37
  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/deleted_source_spec.rb +0 -12
  85. data/spec/faked_project/Gemfile +0 -6
  86. data/spec/faked_project/Rakefile +0 -8
  87. data/spec/faked_project/cucumber.yml +0 -13
  88. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  89. data/spec/faked_project/features/support/env.rb +0 -12
  90. data/spec/faked_project/features/test_stuff.feature +0 -6
  91. data/spec/faked_project/lib/faked_project.rb +0 -11
  92. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  93. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  94. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  95. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  96. data/spec/faked_project/spec/faked_spec.rb +0 -11
  97. data/spec/faked_project/spec/forking_spec.rb +0 -8
  98. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  99. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  100. data/spec/faked_project/spec/spec_helper.rb +0 -11
  101. data/spec/faked_project/test/faked_test.rb +0 -11
  102. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  103. data/spec/faked_project/test/some_class_test.rb +0 -15
  104. data/spec/faked_project/test/test_helper.rb +0 -12
  105. data/spec/file_list_spec.rb +0 -50
  106. data/spec/filters_spec.rb +0 -98
  107. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  108. data/spec/fixtures/app/models/user.rb +0 -10
  109. data/spec/fixtures/deleted_source_sample.rb +0 -15
  110. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  111. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  112. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  113. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  114. data/spec/fixtures/iso-8859.rb +0 -3
  115. data/spec/fixtures/resultset1.rb +0 -4
  116. data/spec/fixtures/resultset2.rb +0 -4
  117. data/spec/fixtures/sample.rb +0 -16
  118. data/spec/fixtures/utf-8.rb +0 -3
  119. data/spec/helper.rb +0 -24
  120. data/spec/merge_helpers_spec.rb +0 -126
  121. data/spec/multi_formatter_spec.rb +0 -20
  122. data/spec/result_spec.rb +0 -209
  123. data/spec/return_codes_spec.rb +0 -34
  124. data/spec/source_file_line_spec.rb +0 -155
  125. data/spec/source_file_spec.rb +0 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 15fa4589e25ee4710bdbcec7485a4d8ec7be7abb
4
- data.tar.gz: a1627cf287ce3c70ba2d60e0943f28f90fcdef79
2
+ SHA256:
3
+ metadata.gz: 6f3e7730302a3a31266a22a830aa6a098e17cc4042f664e4f9a079eef408897f
4
+ data.tar.gz: 423ed5a50493415c4c8bb17ff9c82ffd84e75dc98fc14cc0b4e82f17491d483e
5
5
  SHA512:
6
- metadata.gz: 03a052dcae5923fe19e56f6f20fbd390505f03dca386d51eaca4b525252054856ce492e783e6923ad3b89a46719b89556747b8bbac295513b1d245fba3232e79
7
- data.tar.gz: e2cd84b984e35dfa0c048f375ed2555f08d4df239d616d7c70289b086b1904394b1344f177ad5d7dd08cfb695fe2c22d5375af8e07da5d773500b034d87d4b1c
6
+ metadata.gz: 5b46e9d714b0a675de3b2e42284069942479af4fb0df627b3806fb48e8d373ea7f555fc8cf482682e15e8a6e335ea82358e4b4db28b1257183ae22d018c17f21
7
+ data.tar.gz: 82eedda10bb5786656190ec0ca7dd1a3e18c38f6526db25f90c9b614849e05a14b85a34257343c5f48f62cffc7ddbdb74505b896a7c72236992aadd83c945a24
data/CHANGELOG.md CHANGED
@@ -1,10 +1,106 @@
1
- 0.13.0 2016-01-25 ([changes](https://github.com/colszowka/simplecov/compare/v0.12.0...v0.13.0))
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
+
58
+ 0.15.0 (2017-08-14) ([changes](https://github.com/colszowka/simplecov/compare/v0.14.1...v0.15.0))
59
+ =======
60
+
61
+ ## Enhancements
62
+
63
+ * Ability to use regex filters for removing files from the output. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
64
+
65
+ ## Bugfixes
66
+
67
+ * Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng)
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)
69
+ * Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat)
70
+ * Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
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)
72
+
73
+ 0.14.1 2017-03-18 ([changes](https://github.com/colszowka/simplecov/compare/v0.14.0...v0.14.1))
74
+ ========
75
+
76
+ ## Bugfixes
77
+
78
+ * Files that were skipped as a whole/had no relevant coverage could lead to Float errors. See [#564](https://github.com/colszowka/simplecov/pull/564) (thanks to @stevehanson for the report in [#563](https://github.com/colszowka/simplecov/issues/563))
79
+
80
+ 0.14.0 2017-03-15 ([changes](https://github.com/colszowka/simplecov/compare/v0.13.0...v0.14.0))
81
+ ==========
82
+
83
+ ## Enhancements
84
+
85
+ * Officially support JRuby 9.1+ going forward (should also work with previous releases). See [#547](https://github.com/colszowka/simplecov/pull/547) (ping @PragTob when encountering issues)
86
+ * Add Channel group to Rails profile, when `ActionCable` is loaded. See [#492](https://github.com/colszowka/simplecov/pull/492) (thanks @BenMorganIO)
87
+ * Stop `extend`ing instances of `Array` and `Hash` during merging results avoiding problems frozen results while manually merging results. See [#558](https://github.com/colszowka/simplecov/pull/558) (thanks @aroben)
88
+
89
+ ## Bugfixes
90
+
91
+ * Fix parallel_tests when a thread ends up running no tests. See [#533](https://github.com/colszowka/simplecov/pull/533) (thanks @cshaffer)
92
+ * Skip the `:nocov:` comments along with the code that they skip. See [#551](https://github.com/colszowka/simplecov/pull/551) (thanks @ebiven)
93
+ * Fix crash when Home environment variable is unset. See [#482](https://github.com/colszowka/simplecov/pull/482) (thanks @waldyr)
94
+ * Make track_files work again when explicitly setting it to nil. See [#463](https://github.com/colszowka/simplecov/pull/463) (thanks @craiglittle)
95
+ * Do not overwrite .last_run.json file when refuse_coverage_drop option is enabled and the coverage has dropped (lead to you being able to just rerun tests and everything was _fine_). See [#553](https://github.com/colszowka/simplecov/pull/553) (thanks @Miloshes)
96
+
97
+ 0.13.0 2017-01-25 ([changes](https://github.com/colszowka/simplecov/compare/v0.12.0...v0.13.0))
2
98
  ==========
3
99
 
4
100
  ## Enhancements
5
101
 
6
102
  * Faster run times when a very large number of files is loaded into SimpleCov. See [#520](https://github.com/colszowka/simplecov/pull/520) (thanks @alyssais)
7
- * Only read in source code files that are actually used (faster when files are ignored etc.). See [#540](https://github.com/colszowka/simplecov/pull/540) (tahks @yui-knk)
103
+ * Only read in source code files that are actually used (faster when files are ignored etc.). See [#540](https://github.com/colszowka/simplecov/pull/540) (thanks @yui-knk)
8
104
 
9
105
  ## Bugfixes
10
106
 
@@ -232,7 +328,7 @@ has been added.
232
328
  * Average hits per line for groups of files is now computed correctly.
233
329
  See [#192](http://github.com/colszowka/simplecov/pull/192) and
234
330
  [#179](http://github.com/colszowka/simplecov/issues/179) (thanks to @graysonwright)
235
- * Compatability with BINARY internal encoding.
331
+ * Compatibility with BINARY internal encoding.
236
332
  See [#194](https://github.com/colszowka/simplecov/pull/194) and
237
333
  [#127](https://github.com/colszowka/simplecov/issues/127) (thanks to @justfalter)
238
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!
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2015 Christoph Olszowka
1
+ Copyright (c) 2010-2017 Christoph Olszowka
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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
@@ -40,17 +40,17 @@ automatically when you launch SimpleCov. If you're curious, you can find it [on
40
40
 
41
41
  *Questions, Problems, Suggestions, etc.*
42
42
 
43
- * [Mailing List]: https://groups.google.com/forum/#!forum/simplecov "Open mailing list for discussion and announcements on Google Groups"
43
+ * [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements on Google Groups"
44
44
 
45
45
  Getting started
46
46
  ---------------
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
@@ -66,11 +66,12 @@ Getting started
66
66
  code is required!**
67
67
 
68
68
  SimpleCov must be running in the process that you want the code coverage
69
- analysis to happen on. When testing a server process (i.e. a JSON API
70
- endpoint) via a separate test process (i.e. when using Selenium) where you
69
+ analysis to happen on. When testing a server process (e.g. a JSON API
70
+ endpoint) via a separate test process (e.g. when using Selenium) where you
71
71
  want to see all code executed by the `rails server`, and not just code
72
72
  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):
73
+ to the top of `script/rails` (or `bin/rails` for Rails 4), but below the
74
+ "shebang" line (`#! /usr/bin/env ruby`):
74
75
 
75
76
  ```ruby
76
77
  if ENV['RAILS_ENV'] == 'test'
@@ -79,13 +80,18 @@ Getting started
79
80
  puts "required simplecov"
80
81
  end
81
82
  ```
83
+
82
84
  3. Run your tests, open up `coverage/index.html` in your browser and check out
83
85
  what you've missed so far.
84
86
  4. Add the following to your `.gitignore` file to ensure that coverage results
85
87
  are not tracked by Git (optional):
86
88
 
87
89
  ```
88
- coverage
90
+ echo "coverage" >> .gitignore
91
+ ```
92
+ Or if you use Windows:
93
+ ```
94
+ echo coverage >> .gitignore
89
95
  ```
90
96
 
91
97
  If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles)
@@ -229,11 +235,11 @@ Please check out the [Configuration] API documentation to find out what you can
229
235
 
230
236
  ## Using .simplecov for centralized config
231
237
 
232
- If you use SimpleCov to merge multiple test suite results (i.e. Test/Unit and Cucumber) into a single report, you'd normally have to
238
+ 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
233
239
  set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
234
240
 
235
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
236
- 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`:
237
243
 
238
244
  ```ruby
239
245
  # test/test_helper.rb
@@ -247,6 +253,7 @@ SimpleCov.start 'rails' do
247
253
  # any custom configs like groups and filters can be here at a central place
248
254
  end
249
255
  ```
256
+
250
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.
251
258
 
252
259
  ## Filters
@@ -260,7 +267,7 @@ report.
260
267
 
261
268
  ### Defining custom filters
262
269
 
263
- You can currently define a filter using either a String (that will then be Regexp-matched against each source file's path),
270
+ You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source file's path),
264
271
  a block or by passing in your own Filter class.
265
272
 
266
273
  #### String filter
@@ -273,6 +280,16 @@ end
273
280
 
274
281
  This simple string filter will remove all files that match "/test/" in their path.
275
282
 
283
+ #### Regex filter
284
+
285
+ ```ruby
286
+ SimpleCov.start do
287
+ add_filter %r{^/test/}
288
+ end
289
+ ```
290
+
291
+ This simple regex filter will remove all files that start with /test/ in their path.
292
+
276
293
  #### Block filter
277
294
 
278
295
  ```ruby
@@ -303,6 +320,17 @@ Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter an
303
320
  the filter, a true return value from this method will result in the removal of the given source_file. The filter_argument method
304
321
  is being set in the SimpleCov::Filter initialize method and thus is set to 5 in this example.
305
322
 
323
+ #### Array filter
324
+
325
+ ```ruby
326
+ SimpleCov.start do
327
+ proc = Proc.new { |source_file| false }
328
+ add_filter ["string", /regex/, proc, LineFilter.new(5)]
329
+ end
330
+ ```
331
+
332
+ You can pass in an array containing any of the other filter types.
333
+
306
334
  #### Ignoring/skipping code
307
335
 
308
336
  You can exclude code from the coverage report by wrapping it in `# :nocov:`.
@@ -315,8 +343,7 @@ end
315
343
  # :nocov:
316
344
  ```
317
345
 
318
- The name of the token can be changed to your liking. [Learn more about the nocov feature.][nocov]
319
- [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)
320
347
 
321
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.
322
349
 
@@ -432,7 +459,7 @@ You can deactivate merging altogether with `SimpleCov.use_merging false`.
432
459
 
433
460
  ## Running coverage only on demand
434
461
 
435
- The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (i.e. on a ~10 min Rails test suite, the speed drop was
462
+ The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed drop was
436
463
  only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you run your tests because
437
464
  it doesn't do your test speed any harm and you're always equipped with the latest and greatest coverage results.
438
465
 
@@ -568,10 +595,10 @@ being an instance of SimpleCov::Result. Do whatever your wish with that!
568
595
  As of SimpleCov 0.9, you can specify multiple result formats:
569
596
 
570
597
  ```ruby
571
- SimpleCov.formatters = [
598
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
572
599
  SimpleCov::Formatter::HTMLFormatter,
573
600
  SimpleCov::Formatter::CSVFormatter,
574
- ]
601
+ ])
575
602
  ```
576
603
 
577
604
  ## Available formatters, editor integrations and hosted services
@@ -582,14 +609,11 @@ SimpleCov.formatters = [
582
609
 
583
610
  ## Ruby version compatibility
584
611
 
585
- Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon.
586
- SimpleCov is built against various other Rubies, including Rubinius and JRuby,
587
- in [Continuous Integration], but this happens only to ensure that SimpleCov
588
- does not make your test suite crash right now. Whether SimpleCov will support
589
- JRuby/Rubinius in the future depends solely on whether those Ruby interpreters
590
- add the coverage library.
612
+ 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.
613
+ SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov
614
+ does not make your test suite crash right now.
591
615
 
592
- SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1, and 2.2.
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.
593
617
 
594
618
  ## Want to find dead code in production?
595
619
 
@@ -599,26 +623,49 @@ Try [Coverband](https://github.com/danmayer/coverband).
599
623
 
600
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!
601
625
 
602
- 1. Change the following settings in `development.rb` and `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`.
603
629
 
604
- ```ruby
605
- # Disable Rails's static asset server (Apache or nginx will already do this)
606
- config.serve_static_files = false
607
- config.eager_load = false
608
- ```
609
- 2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb`
610
- (or `rails_helper.rb` for RSpec 3). If you have a `config/spring.rb` file
611
- (or anything similar), add it to the start of such file. Here's a simple
612
- version of what the config should look like:
630
+ ```ruby
631
+ require 'simplecov'
632
+ SimpleCov.start 'rails'
633
+ Rails.application.eager_load!
634
+ ```
613
635
 
614
- ```ruby
615
- if ENV['RAILS_ENV'] == 'test'
616
- require 'simplecov'
617
- SimpleCov.start
618
- end
619
- ```
620
- 3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after
621
- making important changes to your app or its specs!
636
+ Or you could remove `gem 'spring'` from your `Gemfile`.
637
+
638
+ ## Troubleshooting
639
+
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.
643
+
644
+ ```ruby
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
+
663
+ ```
664
+ SimpleCov started successfully!
665
+ MyCode is being loaded!
666
+ ```
667
+
668
+ then it's good otherwise you likely have a problem :)
622
669
 
623
670
  ## Contributing
624
671
 
@@ -630,4 +677,4 @@ Thanks to Aaron Patterson for the original idea for this!
630
677
 
631
678
  ## Copyright
632
679
 
633
- Copyright (c) 2010-2015 Christoph Olszowka. See MIT-LICENSE for details.
680
+ Copyright (c) 2010-2017 Christoph Olszowka. See MIT-LICENSE for details.