simplecov-patched 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +88 -0
  5. data/.travis.yml +29 -0
  6. data/.yardopts +1 -0
  7. data/CHANGELOG.md +435 -0
  8. data/CONTRIBUTING.md +48 -0
  9. data/Gemfile +38 -0
  10. data/MIT-LICENSE +20 -0
  11. data/README.md +646 -0
  12. data/Rakefile +41 -0
  13. data/cucumber.yml +13 -0
  14. data/doc/alternate-formatters.md +36 -0
  15. data/doc/commercial-services.md +20 -0
  16. data/doc/editor-integration.md +13 -0
  17. data/features/config_autoload.feature +46 -0
  18. data/features/config_command_name.feature +45 -0
  19. data/features/config_coverage_dir.feature +33 -0
  20. data/features/config_deactivate_merging.feature +42 -0
  21. data/features/config_formatters.feature +77 -0
  22. data/features/config_merge_timeout.feature +39 -0
  23. data/features/config_nocov_token.feature +79 -0
  24. data/features/config_profiles.feature +44 -0
  25. data/features/config_project_name.feature +27 -0
  26. data/features/config_styles.feature +121 -0
  27. data/features/config_tracked_files.feature +29 -0
  28. data/features/cucumber_basic.feature +29 -0
  29. data/features/maximum_coverage_drop.feature +89 -0
  30. data/features/merging_test_unit_and_rspec.feature +44 -0
  31. data/features/minimum_coverage.feature +59 -0
  32. data/features/refuse_coverage_drop.feature +95 -0
  33. data/features/rspec_basic.feature +32 -0
  34. data/features/rspec_fails_on_initialization.feature +14 -0
  35. data/features/rspec_groups_and_filters_basic.feature +29 -0
  36. data/features/rspec_groups_and_filters_complex.feature +37 -0
  37. data/features/rspec_groups_using_filter_class.feature +41 -0
  38. data/features/rspec_without_simplecov.feature +20 -0
  39. data/features/skipping_code_blocks_manually.feature +70 -0
  40. data/features/step_definitions/html_steps.rb +44 -0
  41. data/features/step_definitions/simplecov_steps.rb +68 -0
  42. data/features/step_definitions/transformers.rb +13 -0
  43. data/features/step_definitions/web_steps.rb +64 -0
  44. data/features/support/env.rb +50 -0
  45. data/features/test_unit_basic.feature +34 -0
  46. data/features/test_unit_groups_and_filters_basic.feature +29 -0
  47. data/features/test_unit_groups_and_filters_complex.feature +35 -0
  48. data/features/test_unit_groups_using_filter_class.feature +40 -0
  49. data/features/test_unit_without_simplecov.feature +20 -0
  50. data/features/unicode_compatiblity.feature +67 -0
  51. data/lib/simplecov.rb +189 -0
  52. data/lib/simplecov/command_guesser.rb +59 -0
  53. data/lib/simplecov/configuration.rb +307 -0
  54. data/lib/simplecov/defaults.rb +121 -0
  55. data/lib/simplecov/exit_codes.rb +8 -0
  56. data/lib/simplecov/file_list.rb +59 -0
  57. data/lib/simplecov/filter.rb +54 -0
  58. data/lib/simplecov/formatter.rb +8 -0
  59. data/lib/simplecov/formatter/multi_formatter.rb +32 -0
  60. data/lib/simplecov/formatter/simple_formatter.rb +23 -0
  61. data/lib/simplecov/jruby_fix.rb +42 -0
  62. data/lib/simplecov/last_run.rb +24 -0
  63. data/lib/simplecov/load_global_config.rb +6 -0
  64. data/lib/simplecov/no_defaults.rb +2 -0
  65. data/lib/simplecov/profiles.rb +31 -0
  66. data/lib/simplecov/railtie.rb +7 -0
  67. data/lib/simplecov/railties/tasks.rake +11 -0
  68. data/lib/simplecov/raw_coverage.rb +39 -0
  69. data/lib/simplecov/result.rb +86 -0
  70. data/lib/simplecov/result_merger.rb +95 -0
  71. data/lib/simplecov/source_file.rb +196 -0
  72. data/lib/simplecov/version.rb +25 -0
  73. data/spec/1_8_fallbacks_spec.rb +31 -0
  74. data/spec/command_guesser_spec.rb +48 -0
  75. data/spec/config_loader_spec.rb +14 -0
  76. data/spec/configuration_spec.rb +35 -0
  77. data/spec/deleted_source_spec.rb +12 -0
  78. data/spec/faked_project/Gemfile +6 -0
  79. data/spec/faked_project/Rakefile +8 -0
  80. data/spec/faked_project/cucumber.yml +13 -0
  81. data/spec/faked_project/features/step_definitions/my_steps.rb +22 -0
  82. data/spec/faked_project/features/support/env.rb +12 -0
  83. data/spec/faked_project/features/test_stuff.feature +6 -0
  84. data/spec/faked_project/lib/faked_project.rb +11 -0
  85. data/spec/faked_project/lib/faked_project/framework_specific.rb +18 -0
  86. data/spec/faked_project/lib/faked_project/meta_magic.rb +24 -0
  87. data/spec/faked_project/lib/faked_project/some_class.rb +28 -0
  88. data/spec/faked_project/lib/faked_project/untested_class.rb +11 -0
  89. data/spec/faked_project/spec/faked_spec.rb +11 -0
  90. data/spec/faked_project/spec/forking_spec.rb +8 -0
  91. data/spec/faked_project/spec/meta_magic_spec.rb +15 -0
  92. data/spec/faked_project/spec/some_class_spec.rb +13 -0
  93. data/spec/faked_project/spec/spec_helper.rb +11 -0
  94. data/spec/faked_project/test/faked_test.rb +11 -0
  95. data/spec/faked_project/test/meta_magic_test.rb +13 -0
  96. data/spec/faked_project/test/some_class_test.rb +15 -0
  97. data/spec/faked_project/test/test_helper.rb +12 -0
  98. data/spec/file_list_spec.rb +50 -0
  99. data/spec/filters_spec.rb +98 -0
  100. data/spec/fixtures/app/controllers/sample_controller.rb +10 -0
  101. data/spec/fixtures/app/models/user.rb +10 -0
  102. data/spec/fixtures/deleted_source_sample.rb +15 -0
  103. data/spec/fixtures/frameworks/rspec_bad.rb +9 -0
  104. data/spec/fixtures/frameworks/rspec_good.rb +9 -0
  105. data/spec/fixtures/frameworks/testunit_bad.rb +9 -0
  106. data/spec/fixtures/frameworks/testunit_good.rb +9 -0
  107. data/spec/fixtures/iso-8859.rb +3 -0
  108. data/spec/fixtures/never.rb +2 -0
  109. data/spec/fixtures/resultset1.rb +4 -0
  110. data/spec/fixtures/resultset2.rb +4 -0
  111. data/spec/fixtures/sample.rb +16 -0
  112. data/spec/fixtures/skipped.rb +4 -0
  113. data/spec/fixtures/skipped_and_executed.rb +8 -0
  114. data/spec/fixtures/utf-8.rb +3 -0
  115. data/spec/helper.rb +26 -0
  116. data/spec/last_run_spec.rb +48 -0
  117. data/spec/multi_formatter_spec.rb +20 -0
  118. data/spec/raw_coverage_spec.rb +92 -0
  119. data/spec/result_merger_spec.rb +96 -0
  120. data/spec/result_spec.rb +209 -0
  121. data/spec/return_codes_spec.rb +34 -0
  122. data/spec/simplecov_spec.rb +110 -0
  123. data/spec/source_file_line_spec.rb +155 -0
  124. data/spec/source_file_spec.rb +141 -0
  125. data/spec/support/fail_rspec_on_ruby_warning.rb +75 -0
  126. metadata +320 -0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,48 @@
1
+ ## Reporting Issues
2
+
3
+ You can report issues at https://github.com/colszowka/simplecov/issues
4
+
5
+ Search existing issues for your problem, chances are someone else already reported it.
6
+
7
+ * Include the SimpleCov version you are running in your report.
8
+ * If you are not running the latest version (please check), and you cannot update it,
9
+ please specify in your report why you can't update to the latest version.
10
+ * Include your `ruby -e "puts RUBY_DESCRIPTION"`.
11
+ * Please also specify the gem versions of Rails (if applicable).
12
+ * 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
+
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!
24
+
25
+ ## Making Contributions
26
+
27
+ To fetch & test the library for development, do:
28
+
29
+ $ git clone https://github.com/colszowka/simplecov.git
30
+ $ cd simplecov
31
+ $ bundle
32
+ $ bundle exec rake
33
+
34
+ If you want to contribute, please:
35
+
36
+ * Fork the project.
37
+ * Make your feature addition or bug fix.
38
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
39
+ * **Bonus Points** go out to anyone who also updates `CHANGELOG.md` :)
40
+ * Send me a pull request on Github.
41
+
42
+ ## Running Individual Tests
43
+
44
+ This project uses Test::Unit. Individual tests can be run like this:
45
+
46
+ ```bash
47
+ ruby -I test path/to/test.rb
48
+ ```
data/Gemfile ADDED
@@ -0,0 +1,38 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Uncomment this to use local copy of simplecov-html in development when checked out
4
+ # gem 'simplecov-html', :path => ::File.dirname(__FILE__) + '/../simplecov-html'
5
+
6
+ # Uncomment this to use development version of html formatter from github
7
+ # gem 'simplecov-html', :github => 'colszowka/simplecov-html'
8
+
9
+ gem "rake", Gem::Version.new(RUBY_VERSION) < Gem::Version.new("1.9.3") ? "~>10.3" : ">= 10.3"
10
+
11
+ group :test do
12
+ gem "rspec", ">= 3.2"
13
+ # Older versions of some gems required for Ruby 1.8.7 support
14
+ platforms :ruby_18 do
15
+ gem "activesupport", "~> 3.2.21"
16
+ gem "i18n", "~> 0.6.11"
17
+ end
18
+ platforms :ruby_18, :ruby_19 do
19
+ gem "mime-types", "~> 1.25"
20
+ gem "addressable", "~> 2.3.0"
21
+ end
22
+ platforms :ruby_18, :ruby_19, :ruby_20, :ruby_21 do
23
+ gem "rack", "~> 1.6"
24
+ end
25
+ platforms :jruby, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25 do
26
+ gem "aruba", "~> 0.7.4"
27
+ gem "capybara"
28
+ gem "nokogiri", RUBY_VERSION < "2.1" ? "~> 1.6.0" : ">= 1.7"
29
+ gem "cucumber"
30
+ gem "phantomjs", "~> 2.1"
31
+ gem "poltergeist"
32
+ gem "rubocop", "0.48.1" unless RUBY_VERSION.start_with?("1.")
33
+ gem "test-unit"
34
+ end
35
+ gem "json", RUBY_VERSION.start_with?("1.") ? "~> 1.8" : "~> 2.0"
36
+ end
37
+
38
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2015 Christoph Olszowka
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,646 @@
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)
2
+ =========
3
+ **Code coverage for Ruby**
4
+
5
+ ### patches
6
+
7
+ simplecov-patched is the upstream simplecov master branch with the following patches applied:
8
+
9
+ - `git am -3 https://github.com/colszowka/simplecov/pull/570`
10
+
11
+ ---
12
+
13
+ * [Source Code]
14
+ * [API documentation]
15
+ * [Changelog]
16
+ * [Rubygem]
17
+ * [Continuous Integration]
18
+
19
+ [Coverage]: http://www.ruby-doc.org/stdlib-2.1.0/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
20
+ [Source Code]: https://github.com/colszowka/simplecov "Source Code @ GitHub"
21
+ [API documentation]: http://rubydoc.info/gems/simplecov/frames "RDoc API Documentation at Rubydoc.info"
22
+ [Configuration]: http://rubydoc.info/gems/simplecov/SimpleCov/Configuration "Configuration options API documentation"
23
+ [Changelog]: https://github.com/colszowka/simplecov/blob/master/CHANGELOG.md "Project Changelog"
24
+ [Rubygem]: http://rubygems.org/gems/simplecov "SimpleCov @ rubygems.org"
25
+ [Continuous Integration]: http://travis-ci.org/colszowka/simplecov "SimpleCov is built around the clock by travis-ci.org"
26
+ [Dependencies]: https://gemnasium.com/colszowka/simplecov "SimpleCov dependencies on Gemnasium"
27
+ [simplecov-html]: https://github.com/colszowka/simplecov-html "SimpleCov HTML Formatter Source Code @ GitHub"
28
+
29
+ SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Coverage][Coverage] library to gather code
30
+ coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format,
31
+ and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of
32
+ code.
33
+
34
+ In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features,
35
+ etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your
36
+ report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
37
+
38
+ The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and configured
39
+ automatically when you launch SimpleCov. If you're curious, you can find it [on Github, too][simplecov-html].
40
+
41
+
42
+ ## Contact
43
+
44
+ *Code and Bug Reports*
45
+
46
+ * [Issue Tracker](https://github.com/colszowka/simplecov/issues)
47
+ * 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.
48
+
49
+ *Questions, Problems, Suggestions, etc.*
50
+
51
+ * [Mailing List]: https://groups.google.com/forum/#!forum/simplecov "Open mailing list for discussion and announcements on Google Groups"
52
+
53
+ Getting started
54
+ ---------------
55
+ 1. Add SimpleCov to your `Gemfile` and `bundle install`:
56
+
57
+ ```ruby
58
+ gem 'simplecov', :require => false, :group => :test
59
+ ```
60
+ 2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb`
61
+ (*or `spec_helper.rb`, cucumber `env.rb`, or whatever your preferred test
62
+ framework uses*):
63
+
64
+ ```ruby
65
+ require 'simplecov'
66
+ SimpleCov.start
67
+
68
+ # Previous content of test helper now starts here
69
+ ```
70
+
71
+ **Note:** If SimpleCov starts after your application code is already loaded
72
+ (via `require`), it won't be able to track your files and their coverage!
73
+ The `SimpleCov.start` **must** be issued **before any of your application
74
+ code is required!**
75
+
76
+ SimpleCov must be running in the process that you want the code coverage
77
+ analysis to happen on. When testing a server process (e.g. a JSON API
78
+ endpoint) via a separate test process (e.g. when using Selenium) where you
79
+ want to see all code executed by the `rails server`, and not just code
80
+ executed in your actual test files, you'll want to add something like this
81
+ to the top of `script/rails` (or `bin/rails` for Rails 4), but below the
82
+ "shebang" line (`#! /usr/bin/env ruby`):
83
+
84
+ ```ruby
85
+ if ENV['RAILS_ENV'] == 'test'
86
+ require 'simplecov'
87
+ SimpleCov.start 'rails'
88
+ puts "required simplecov"
89
+ end
90
+ ```
91
+
92
+ 3. Run your tests, open up `coverage/index.html` in your browser and check out
93
+ what you've missed so far.
94
+ 4. Add the following to your `.gitignore` file to ensure that coverage results
95
+ are not tracked by Git (optional):
96
+
97
+ ```
98
+ coverage
99
+ ```
100
+
101
+ If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles)
102
+ that will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of
103
+ your test_helper should be like this:
104
+
105
+ ```ruby
106
+ require 'simplecov'
107
+ SimpleCov.start 'rails'
108
+ ```
109
+
110
+ ## Example output
111
+
112
+ **Coverage results report, fully browsable locally with sorting and much more:**
113
+
114
+ ![SimpleCov coverage report](https://cloud.githubusercontent.com/assets/137793/17071162/db6f253e-502d-11e6-9d84-e40c3d75f333.png)
115
+
116
+
117
+ **Source file coverage details view:**
118
+
119
+ ![SimpleCov source file detail view](https://cloud.githubusercontent.com/assets/137793/17071163/db6f9f0a-502d-11e6-816c-edb2c66fad8d.png)
120
+
121
+ ## Use it with any framework!
122
+
123
+ Similarly to the usage with Test::Unit described above, the only thing you have to do is to add the SimpleCov
124
+ config to the very top of your Cucumber/RSpec/whatever setup file.
125
+
126
+ Add the setup code to the **top** of `features/support/env.rb` (for Cucumber) or `spec/spec_helper.rb` (for RSpec).
127
+ Other test frameworks should work accordingly, whatever their setup file may be:
128
+
129
+ ```ruby
130
+ require 'simplecov'
131
+ SimpleCov.start 'rails'
132
+ ```
133
+
134
+ You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov does not
135
+ care what kind of framework it is running in; it just looks at what code is being executed and generates a report about it.
136
+
137
+ ### Notes on specific frameworks and test utilities
138
+
139
+ For some frameworks and testing tools there are quirks and problems you might want to know about if you want
140
+ to use SimpleCov with them. Here's an overview of the known ones:
141
+
142
+ <table>
143
+ <tr><th>Framework</th><th>Notes</th><th>Issue</th></tr>
144
+ <tr>
145
+ <th>
146
+ parallel_tests
147
+ </th>
148
+ <td>
149
+ As of 0.8.0, SimpleCov should correctly recognize parallel_tests and
150
+ supplement your test suite names with their corresponding test env
151
+ numbers. SimpleCov locks the resultset cache while merging, ensuring no
152
+ race conditions occur when results are merged.
153
+ </td>
154
+ <td>
155
+ <a href="https://github.com/colszowka/simplecov/issues/64">#64</a> &amp;
156
+ <a href="https://github.com/colszowka/simplecov/pull/185">#185</a>
157
+ </td>
158
+ </tr>
159
+ <tr>
160
+ <th>
161
+ RubyMine
162
+ </th>
163
+ <td>
164
+ The <a href="https://www.jetbrains.com/ruby/">RubyMine IDE</a> has
165
+ built-in support for SimpleCov's coverage reports, though you might need
166
+ to explicitly set the output root using `SimpleCov.root('foo/bar/baz')`
167
+ </td>
168
+ <td>
169
+ <a href="https://github.com/colszowka/simplecov/issues/95">#95</a>
170
+ </td>
171
+ </tr>
172
+ <tr>
173
+ <th>
174
+ Spork
175
+ </th>
176
+ <td>
177
+ Because of how Spork works internally (using preforking), there used to
178
+ be trouble when using SimpleCov with it, but that has apparently been
179
+ resolved with a specific configuration strategy. See <a
180
+ href="https://github.com/colszowka/simplecov/issues/42#issuecomment-4440284">this</a>
181
+ comment.
182
+ </td>
183
+ <td>
184
+ <a href="https://github.com/colszowka/simplecov/issues/42#issuecomment-4440284">#42</a>
185
+ </td>
186
+ </tr>
187
+ <tr>
188
+ <th>
189
+ Spring
190
+ </th>
191
+ <td>
192
+ <a href="#want-to-use-spring-with-simplecov">See section below.</a>
193
+ </td>
194
+ <td>
195
+ <a href="https://github.com/colszowka/simplecov/issues/381">#381</a>
196
+ </td>
197
+ </tr>
198
+ <tr>
199
+ <th>
200
+ Test/Unit
201
+ </th>
202
+ <td>
203
+ Test Unit 2 used to mess with ARGV, leading to a failure to detect the
204
+ test process name in SimpleCov. <code>test-unit</code> releases 2.4.3+
205
+ (Dec 11th, 2011) should have this problem resolved.
206
+ </td>
207
+ <td>
208
+ <a href="https://github.com/colszowka/simplecov/issues/45">#45</a> &amp;
209
+ <a href="https://github.com/test-unit/test-unit/pull/12">test-unit/test-unit#12</a>
210
+ </td>
211
+ </tr>
212
+ </table>
213
+
214
+ ## Configuring SimpleCov
215
+
216
+ [Configuration] settings can be applied in three formats, which are completely equivalent:
217
+
218
+ * The most common way is to configure it directly in your start block:
219
+
220
+ ```ruby
221
+ SimpleCov.start do
222
+ some_config_option 'foo'
223
+ end
224
+ ```
225
+ * You can also set all configuration options directly:
226
+
227
+ ```ruby
228
+ SimpleCov.some_config_option 'foo'
229
+ ```
230
+ * If you do not want to start coverage immediately after launch or want to add additional configuration later on in a concise way, use:
231
+
232
+ ```ruby
233
+ SimpleCov.configure do
234
+ some_config_option 'foo'
235
+ end
236
+ ```
237
+
238
+ Please check out the [Configuration] API documentation to find out what you can customize.
239
+
240
+ ## Using .simplecov for centralized config
241
+
242
+ 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
243
+ set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
244
+
245
+ To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the `require 'simplecov'` in each
246
+ test setup helper and move the `SimpleCov.start` code with all your custom config options into `.simplecov`:
247
+
248
+ ```ruby
249
+ # test/test_helper.rb
250
+ require 'simplecov'
251
+
252
+ # features/support/env.rb
253
+ require 'simplecov'
254
+
255
+ # .simplecov
256
+ SimpleCov.start 'rails' do
257
+ # any custom configs like groups and filters can be here at a central place
258
+ end
259
+ ```
260
+ 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.
261
+
262
+ ## Filters
263
+
264
+ Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all files
265
+ OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source files in the
266
+ gems you are using.
267
+
268
+ You can define your own to remove things like configuration files, tests or whatever you don't need in your coverage
269
+ report.
270
+
271
+ ### Defining custom filters
272
+
273
+ You can currently define a filter using either a String (that will then be Regexp-matched against each source file's path),
274
+ a block or by passing in your own Filter class.
275
+
276
+ #### String filter
277
+
278
+ ```ruby
279
+ SimpleCov.start do
280
+ add_filter "/test/"
281
+ end
282
+ ```
283
+
284
+ This simple string filter will remove all files that match "/test/" in their path.
285
+
286
+ #### Block filter
287
+
288
+ ```ruby
289
+ SimpleCov.start do
290
+ add_filter do |source_file|
291
+ source_file.lines.count < 5
292
+ end
293
+ end
294
+ ```
295
+
296
+ Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be removed
297
+ from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to learn about the
298
+ methods available to you. In the above example, the filter will remove all files that have less than 5 lines of code.
299
+
300
+ #### Custom filter class
301
+
302
+ ```ruby
303
+ class LineFilter < SimpleCov::Filter
304
+ def matches?(source_file)
305
+ source_file.lines.count < filter_argument
306
+ end
307
+ end
308
+
309
+ SimpleCov.add_filter LineFilter.new(5)
310
+ ```
311
+
312
+ Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method 'matches?(source_file)'. When running
313
+ the filter, a true return value from this method will result in the removal of the given source_file. The filter_argument method
314
+ is being set in the SimpleCov::Filter initialize method and thus is set to 5 in this example.
315
+
316
+ #### Ignoring/skipping code
317
+
318
+ You can exclude code from the coverage report by wrapping it in `# :nocov:`.
319
+
320
+ ```ruby
321
+ # :nocov:
322
+ def skip_this_method
323
+ never_reached
324
+ end
325
+ # :nocov:
326
+ ```
327
+
328
+ The name of the token can be changed to your liking. [Learn more about the nocov feature.][nocov]
329
+ [nocov]: https://github.com/colszowka/simplecov/blob/master/features/config_nocov_token.feature
330
+
331
+ **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.
332
+
333
+ ## Default root filter and coverage for things outside of it
334
+
335
+ By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want
336
+ to include coverage reports for things you include as a gem, for example a Rails Engine.
337
+
338
+ Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/colszowka/simplecov/issues/221)
339
+ that shows how you can achieve just that:
340
+
341
+ ```ruby
342
+ SimpleCov.start :rails do
343
+ filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults
344
+ add_filter do |src|
345
+ !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /my_engine/
346
+ end
347
+ end
348
+ ```
349
+
350
+ ## Groups
351
+
352
+ You can separate your source files into groups. For example, in a Rails app, you'll want to have separate listings for
353
+ Models, Controllers, Helpers, and Libs. Group definition works similarly to Filters (and also accepts custom
354
+ filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering results,
355
+ which exclude files from results when the filter results in a true value.
356
+
357
+ Add your groups with:
358
+
359
+ ```ruby
360
+ SimpleCov.start do
361
+ add_group "Models", "app/models"
362
+ add_group "Controllers", "app/controllers"
363
+ add_group "Long files" do |src_file|
364
+ src_file.lines.count > 100
365
+ end
366
+ add_group "Multiple Files", ["app/models", "app/controllers"] # You can also pass in an array
367
+ add_group "Short files", LineFilter.new(5) # Using the LineFilter class defined in Filters section above
368
+ end
369
+ ```
370
+
371
+ ## Merging results
372
+
373
+ You normally want to have your coverage analyzed across ALL of your test suites, right?
374
+
375
+ Simplecov automatically caches coverage results in your (coverage_path)/.resultset.json. Those results will then
376
+ be automatically merged when generating the result, so when coverage is set up properly for Cucumber and your
377
+ unit / functional / integration tests, all of those test suites will be taken into account when building the
378
+ coverage report.
379
+
380
+ There are two things to note here though:
381
+
382
+ ### Test suite names
383
+
384
+ SimpleCov tries to guess the name of the currently running test suite based upon the shell command the tests
385
+ are running on. This should work fine for Unit Tests, RSpec, and Cucumber. If it fails, it will use the shell
386
+ command that invoked the test suite as a command name.
387
+
388
+ If you have some non-standard setup and still want nicely labeled test suites, you have to give Simplecov a
389
+ cue as to what the name of the currently running test suite is. You can do so by specifying
390
+ `SimpleCov.command_name` in one test file that is part of your specific suite.
391
+
392
+ To customize the suite names on a Rails app (yeah, sorry for being Rails-biased, but everyone knows what
393
+ the structure of those projects is. You can apply this accordingly to the RSpecs in your
394
+ Outlook-WebDAV-Calendar-Sync gem), you could do something like this:
395
+
396
+ ```ruby
397
+ # test/unit/some_test.rb
398
+ SimpleCov.command_name 'test:units'
399
+
400
+ # test/functionals/some_controller_test.rb
401
+ SimpleCov.command_name "test:functionals"
402
+
403
+ # test/integration/some_integration_test.rb
404
+ SimpleCov.command_name "test:integration"
405
+
406
+ # features/support/env.rb
407
+ SimpleCov.command_name "features"
408
+ ```
409
+
410
+ Note that this only has to be invoked ONCE PER TEST SUITE, so even if you have 200 unit test files,
411
+ specifying it in `some_test.rb` is enough.
412
+
413
+ Last but not least **if multiple suites resolve to the same `command_name`** be aware that the coverage results **will
414
+ clobber each other instead of being merged**. SimpleCov is smart enough to detect unique names for the most common
415
+ setups, but if you have more than one test suite that doesn't follow a common pattern then you will want to manually
416
+ ensure that each suite gets a unique `command_name`.
417
+
418
+ If you are running tests in parallel each process has the potential to clobber results from the other test processes.
419
+ If you are relying on the default `command_name` then SimpleCov will attempt to detect and avoid parallel test suite
420
+ `command_name` collisions based on the presence of `ENV['PARALLEL_TEST_GROUPS']` and `ENV['TEST_ENV_NUMBER']`. If your
421
+ parallel test runner does not set one or both of these then *you must* set a `command_name` and ensure that it is unique
422
+ per process (eg. `command_name "Unit Tests PID #{$$}"`).
423
+
424
+ If you are using parallel_tests, you must incorporate `TEST_ENV_NUMBER` into the command name yourself, in
425
+ order for SimpleCov to merge the results correctly. For example:
426
+
427
+ ```ruby
428
+ # spec/spec_helper.rb
429
+ SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '')
430
+ ```
431
+
432
+ [simplecov-html] prints the used test suites in the footer of the generated coverage report.
433
+
434
+ ### Timeout for merge
435
+
436
+ Of course, your cached coverage data is likely to become invalid at some point. Thus, result sets that are older than
437
+ `SimpleCov.merge_timeout` will not be used any more. By default, the timeout is 600 seconds (10 minutes), and you can
438
+ raise (or lower) it by specifying `SimpleCov.merge_timeout 3600` (1 hour), or, inside a configure/start block, with
439
+ just `merge_timeout 3600`.
440
+
441
+ You can deactivate merging altogether with `SimpleCov.use_merging false`.
442
+
443
+ ## Running coverage only on demand
444
+
445
+ The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed drop was
446
+ only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you run your tests because
447
+ it doesn't do your test speed any harm and you're always equipped with the latest and greatest coverage results.
448
+
449
+ Because of this, SimpleCov has no explicit built-in mechanism to run coverage only on demand.
450
+
451
+ However, you can still accomplish this very easily by introducing an ENV variable conditional into your SimpleCov setup block, like this:
452
+
453
+ ```ruby
454
+ SimpleCov.start if ENV["COVERAGE"]
455
+ ```
456
+
457
+ Then, SimpleCov will only run if you execute your tests like this:
458
+
459
+ ```shell
460
+ COVERAGE=true rake test
461
+ ```
462
+
463
+ ## Profiles
464
+
465
+ By default, SimpleCov's only config assumption is that you only want coverage reports for files inside your project
466
+ root. To save yourself from repetitive configuration, you can use predefined blocks of configuration, called 'profiles',
467
+ or define your own.
468
+
469
+ You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov
470
+ comes bundled with a 'rails' profile. It looks somewhat like this:
471
+
472
+ ```ruby
473
+ SimpleCov.profiles.define 'rails' do
474
+ add_filter '/test/'
475
+ add_filter '/config/'
476
+
477
+ add_group 'Controllers', 'app/controllers'
478
+ add_group 'Models', 'app/models'
479
+ add_group 'Helpers', 'app/helpers'
480
+ add_group 'Libraries', 'lib'
481
+ end
482
+ ```
483
+
484
+ As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch SimpleCov with:
485
+
486
+ ```ruby
487
+ SimpleCov.start 'rails'
488
+ ```
489
+
490
+ or
491
+
492
+ ```ruby
493
+ SimpleCov.start 'rails' do
494
+ # additional config here
495
+ end
496
+ ```
497
+
498
+ ### Custom profiles
499
+
500
+ You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an existing
501
+ profile and customize it so you can reuse it in unit tests and Cucumber features. For example:
502
+
503
+ ```ruby
504
+ # lib/simplecov_custom_profile.rb
505
+ require 'simplecov'
506
+ SimpleCov.profiles.define 'myprofile' do
507
+ load_profile 'rails'
508
+ add_filter 'vendor' # Don't include vendored stuff
509
+ end
510
+
511
+ # features/support/env.rb
512
+ require 'simplecov_custom_profile'
513
+ SimpleCov.start 'myprofile'
514
+
515
+ # test/test_helper.rb
516
+ require 'simplecov_custom_profile'
517
+ SimpleCov.start 'myprofile'
518
+ ```
519
+
520
+ ## Customizing exit behaviour
521
+
522
+ You can define what SimpleCov should do when your test suite finishes by customizing the at_exit hook:
523
+
524
+ ```ruby
525
+ SimpleCov.at_exit do
526
+ SimpleCov.result.format!
527
+ end
528
+ ```
529
+
530
+ Above is the default behaviour. Do whatever you like instead!
531
+
532
+ ### Minimum coverage
533
+
534
+ You can define the minimum coverage percentage expected. SimpleCov will return non-zero if unmet.
535
+
536
+ ```ruby
537
+ SimpleCov.minimum_coverage 90
538
+ ```
539
+
540
+ ### Minimum coverage by file
541
+
542
+ 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.
543
+
544
+ ```ruby
545
+ SimpleCov.minimum_coverage_by_file 80
546
+ ```
547
+
548
+ ### Maximum coverage drop
549
+
550
+ You can define the maximum coverage drop percentage at once. SimpleCov will return non-zero if exceeded.
551
+
552
+ ```ruby
553
+ SimpleCov.maximum_coverage_drop 5
554
+ ```
555
+
556
+ ### Refuse dropping coverage
557
+
558
+ You can also entirely refuse dropping coverage between test runs:
559
+
560
+ ```ruby
561
+ SimpleCov.refuse_coverage_drop
562
+ ```
563
+
564
+ ## Using your own formatter
565
+
566
+ You can use your own formatter with:
567
+
568
+ ```ruby
569
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
570
+ ```
571
+
572
+ When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result), "result"
573
+ being an instance of SimpleCov::Result. Do whatever your wish with that!
574
+
575
+
576
+ ## Using multiple formatters
577
+
578
+ As of SimpleCov 0.9, you can specify multiple result formats:
579
+
580
+ ```ruby
581
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
582
+ SimpleCov::Formatter::HTMLFormatter,
583
+ SimpleCov::Formatter::CSVFormatter,
584
+ ])
585
+ ```
586
+
587
+ ## Available formatters, editor integrations and hosted services
588
+
589
+ * [Open Source formatter and integration plugins for SimpleCov](doc/alternate-formatters.md)
590
+ * [Editor Integration](doc/editor-integration.md)
591
+ * [Hosted (commercial) services](doc/commercial-services.md)
592
+
593
+ ## Ruby version compatibility
594
+
595
+ 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.
596
+ SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov
597
+ does not make your test suite crash right now.
598
+
599
+ 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.
600
+
601
+ ## Want to find dead code in production?
602
+
603
+ Try [Coverband](https://github.com/danmayer/coverband).
604
+
605
+ ## Want to use Spring with SimpleCov?
606
+
607
+ 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!
608
+
609
+ 1. Change the following settings in `test.rb`.
610
+
611
+ ```ruby
612
+ # For Rails 4 or earlier, use the following configuration:
613
+ # Disable Rails's static asset server (Apache or nginx will already do this)
614
+ config.serve_static_files = false
615
+ config.eager_load = false
616
+
617
+ # For Rails 5, use the following configuration:
618
+ # Disable Rails's static asset server (Apache or nginx will already do this)
619
+ config.public_file_server.enabled = false
620
+ config.eager_load = false
621
+ ```
622
+ 2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb`
623
+ (or `rails_helper.rb` for RSpec 3). If you have a `config/spring.rb` file
624
+ (or anything similar), add it to the start of such file. Here's a simple
625
+ version of what the config should look like:
626
+
627
+ ```ruby
628
+ if ENV['RAILS_ENV'] == 'test'
629
+ require 'simplecov'
630
+ SimpleCov.start
631
+ end
632
+ ```
633
+ 3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after
634
+ making important changes to your app or its specs!
635
+
636
+ ## Contributing
637
+
638
+ See the [contributing guide](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md).
639
+
640
+ ## Kudos
641
+
642
+ Thanks to Aaron Patterson for the original idea for this!
643
+
644
+ ## Copyright
645
+
646
+ Copyright (c) 2010-2015 Christoph Olszowka. See MIT-LICENSE for details.