simplecov 0.6.4 → 0.17.1

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