simplecov 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -4
- data/CHANGELOG.md +19 -2
- data/Gemfile +1 -1
- data/README.md +18 -13
- data/Rakefile +1 -1
- data/features/config_nocov_token.feature +2 -2
- data/features/maximum_coverage_drop.feature +54 -1
- data/features/refuse_coverage_drop.feature +61 -1
- data/features/skipping_code_blocks_manually.feature +2 -2
- data/features/step_definitions/simplecov_steps.rb +1 -1
- data/lib/simplecov.rb +3 -3
- data/lib/simplecov/configuration.rb +27 -16
- data/lib/simplecov/defaults.rb +9 -10
- data/lib/simplecov/last_run.rb +3 -1
- data/lib/simplecov/load_global_config.rb +6 -0
- data/lib/simplecov/raw_coverage.rb +39 -0
- data/lib/simplecov/result.rb +0 -1
- data/lib/simplecov/result_merger.rb +12 -8
- data/lib/simplecov/source_file.rb +35 -33
- data/lib/simplecov/version.rb +1 -1
- data/spec/config_loader_spec.rb +14 -0
- data/spec/configuration_spec.rb +35 -0
- data/spec/faked_project/features/step_definitions/my_steps.rb +1 -1
- data/spec/faked_project/features/test_stuff.feature +1 -1
- data/spec/file_list_spec.rb +4 -4
- data/spec/helper.rb +3 -1
- data/spec/last_run_spec.rb +48 -0
- data/spec/raw_coverage_spec.rb +92 -0
- data/spec/{merge_helpers_spec.rb → result_merger_spec.rb} +2 -40
- data/spec/source_file_spec.rb +4 -4
- data/spec/support/fail_rspec_on_ruby_warning.rb +75 -0
- metadata +10 -4
- data/lib/simplecov/merge_helpers.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e97e7dcf1f3c003a18fe662722aa6afb4c22a4f
|
4
|
+
data.tar.gz: 53416d84e2f00e0d4b9da2a9ffd8f92f01eaf084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5553c580dc83af525bde5a86cba9648a0bb61a5340d5047f17aaf0c933375a4594b5b0094321374e3215d2dd617717e9d5aa0b8c27fe9a2937b06cf2eb757700
|
7
|
+
data.tar.gz: 290a8fd21178bbb5cf125a8b06d3ac844cc886c56bda739bb3056166b760afef308c1504cdde5277cc7ebfb877abbb505353b71bf0f9be3b9b2dfc9977cce580
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,27 @@
|
|
1
|
-
0.
|
1
|
+
0.14.0 2017-03-15 ([changes](https://github.com/colszowka/simplecov/compare/v0.13.0...v0.14.0))
|
2
|
+
==========
|
3
|
+
|
4
|
+
## Enhancements
|
5
|
+
|
6
|
+
* 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)
|
7
|
+
* Add Channel group to Rails profile, when `ActionCable` is loaded. See [#492](https://github.com/colszowka/simplecov/pull/492) (thanks @BenMorganIO)
|
8
|
+
* 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)
|
9
|
+
|
10
|
+
## Bugfixes
|
11
|
+
|
12
|
+
* Fix parallel_tests when a thread ends up running no tests. See [#533](https://github.com/colszowka/simplecov/pull/533) (thanks @cshaffer)
|
13
|
+
* Skip the `:nocov:` comments along with the code that they skip. See [#551](https://github.com/colszowka/simplecov/pull/551) (thanks @ebiven)
|
14
|
+
* Fix crash when Home environment variable is unset. See [#482](https://github.com/colszowka/simplecov/pull/482) (thanks @waldyr)
|
15
|
+
* Make track_files work again when explicitly setting it to nil. See [#463](https://github.com/colszowka/simplecov/pull/463) (thanks @craiglittle)
|
16
|
+
* 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)
|
17
|
+
|
18
|
+
0.13.0 2017-01-25 ([changes](https://github.com/colszowka/simplecov/compare/v0.12.0...v0.13.0))
|
2
19
|
==========
|
3
20
|
|
4
21
|
## Enhancements
|
5
22
|
|
6
23
|
* 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) (
|
24
|
+
* 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
25
|
|
9
26
|
## Bugfixes
|
10
27
|
|
data/Gemfile
CHANGED
@@ -27,7 +27,7 @@ group :test do
|
|
27
27
|
gem "capybara"
|
28
28
|
gem "nokogiri", RUBY_VERSION < "2.1" ? "~> 1.6.0" : ">= 1.7"
|
29
29
|
gem "cucumber"
|
30
|
-
gem "phantomjs", "~> 1
|
30
|
+
gem "phantomjs", "~> 2.1"
|
31
31
|
gem "poltergeist"
|
32
32
|
gem "rubocop" unless RUBY_VERSION.start_with?("1.")
|
33
33
|
gem "test-unit"
|
data/README.md
CHANGED
@@ -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 (
|
70
|
-
endpoint) via a separate test process (
|
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,6 +80,7 @@ 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
|
@@ -229,7 +231,7 @@ Please check out the [Configuration] API documentation to find out what you can
|
|
229
231
|
|
230
232
|
## Using .simplecov for centralized config
|
231
233
|
|
232
|
-
If you use SimpleCov to merge multiple test suite results (
|
234
|
+
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
235
|
set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
|
234
236
|
|
235
237
|
To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the `require 'simplecov'` in each
|
@@ -432,7 +434,7 @@ You can deactivate merging altogether with `SimpleCov.use_merging false`.
|
|
432
434
|
|
433
435
|
## Running coverage only on demand
|
434
436
|
|
435
|
-
The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (
|
437
|
+
The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed drop was
|
436
438
|
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
439
|
it doesn't do your test speed any harm and you're always equipped with the latest and greatest coverage results.
|
438
440
|
|
@@ -582,14 +584,11 @@ SimpleCov.formatters = [
|
|
582
584
|
|
583
585
|
## Ruby version compatibility
|
584
586
|
|
585
|
-
Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon.
|
586
|
-
SimpleCov is built against
|
587
|
-
|
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.
|
587
|
+
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.
|
588
|
+
SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov
|
589
|
+
does not make your test suite crash right now.
|
591
590
|
|
592
|
-
SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1,
|
591
|
+
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.
|
593
592
|
|
594
593
|
## Want to find dead code in production?
|
595
594
|
|
@@ -599,12 +598,18 @@ Try [Coverband](https://github.com/danmayer/coverband).
|
|
599
598
|
|
600
599
|
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
600
|
|
602
|
-
1. Change the following settings in `
|
601
|
+
1. Change the following settings in `test.rb`.
|
603
602
|
|
604
603
|
```ruby
|
604
|
+
# For Rails 4 or earlier, use the following configuration:
|
605
605
|
# Disable Rails's static asset server (Apache or nginx will already do this)
|
606
606
|
config.serve_static_files = false
|
607
607
|
config.eager_load = false
|
608
|
+
|
609
|
+
# For Rails 5, use the following configuration:
|
610
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
611
|
+
config.public_file_server.enabled = false
|
612
|
+
config.eager_load = false
|
608
613
|
```
|
609
614
|
2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb`
|
610
615
|
(or `rails_helper.rb` for RSpec 3). If you have a `config/spring.rb` file
|
data/Rakefile
CHANGED
@@ -36,7 +36,7 @@ Feature:
|
|
36
36
|
| lib/faked_project/meta_magic.rb | 100.0 % |
|
37
37
|
| lib/faked_project/nocov.rb | 100.0 % |
|
38
38
|
|
39
|
-
And there should be
|
39
|
+
And there should be 7 skipped lines in the source files
|
40
40
|
|
41
41
|
And the report should be based upon:
|
42
42
|
| Unit Tests |
|
@@ -73,7 +73,7 @@ Feature:
|
|
73
73
|
| lib/faked_project/meta_magic.rb | 100.0 % |
|
74
74
|
| lib/faked_project/nocov.rb | 100.0 % |
|
75
75
|
|
76
|
-
And there should be
|
76
|
+
And there should be 7 skipped lines in the source files
|
77
77
|
|
78
78
|
And the report should be based upon:
|
79
79
|
| Unit Tests |
|
@@ -4,7 +4,7 @@ Feature:
|
|
4
4
|
Exit code should be non-zero if the overall coverage decreases by more than
|
5
5
|
the maximum_coverage_drop threshold.
|
6
6
|
|
7
|
-
Scenario:
|
7
|
+
Scenario: maximum_coverage_drop configured cam cause spec failure
|
8
8
|
Given SimpleCov for Test/Unit is configured with:
|
9
9
|
"""
|
10
10
|
require 'simplecov'
|
@@ -33,4 +33,57 @@ Feature:
|
|
33
33
|
Then the exit status should not be 0
|
34
34
|
And the output should contain "Coverage has dropped by 3.32% since the last time (maximum allowed: 3.14%)."
|
35
35
|
And a file named "coverage/.last_run.json" should exist
|
36
|
+
And the file "coverage/.last_run.json" should contain:
|
37
|
+
"""
|
38
|
+
{
|
39
|
+
"result": {
|
40
|
+
"covered_percent": 88.1
|
41
|
+
}
|
42
|
+
}
|
43
|
+
"""
|
44
|
+
|
45
|
+
Scenario: maximum_coverage_drop not configured updates resultset
|
46
|
+
Given SimpleCov for Test/Unit is configured with:
|
47
|
+
"""
|
48
|
+
require 'simplecov'
|
49
|
+
SimpleCov.start do
|
50
|
+
add_filter 'test.rb'
|
51
|
+
end
|
52
|
+
"""
|
53
|
+
|
54
|
+
When I run `bundle exec rake test`
|
55
|
+
Then the exit status should be 0
|
56
|
+
And a file named "coverage/.last_run.json" should exist
|
57
|
+
And the file "coverage/.last_run.json" should contain:
|
58
|
+
"""
|
59
|
+
{
|
60
|
+
"result": {
|
61
|
+
"covered_percent": 88.1
|
62
|
+
}
|
63
|
+
}
|
64
|
+
"""
|
65
|
+
|
66
|
+
Given a file named "lib/faked_project/missed.rb" with:
|
67
|
+
"""
|
68
|
+
class UncoveredSourceCode
|
69
|
+
def foo
|
70
|
+
never_reached
|
71
|
+
rescue => err
|
72
|
+
but no one cares about invalid ruby here
|
73
|
+
end
|
74
|
+
end
|
75
|
+
"""
|
76
|
+
|
77
|
+
When I run `bundle exec rake test`
|
78
|
+
Then the exit status should be 0
|
79
|
+
And a file named "coverage/.last_run.json" should exist
|
80
|
+
And the file "coverage/.last_run.json" should contain:
|
81
|
+
"""
|
82
|
+
{
|
83
|
+
"result": {
|
84
|
+
"covered_percent": 84.78
|
85
|
+
}
|
86
|
+
}
|
87
|
+
"""
|
88
|
+
|
36
89
|
|
@@ -2,8 +2,9 @@
|
|
2
2
|
Feature:
|
3
3
|
|
4
4
|
Exit code should be non-zero if the overall coverage decreases.
|
5
|
+
And last_run file should not be overwritten with new coverage value.
|
5
6
|
|
6
|
-
Scenario:
|
7
|
+
Scenario: refuse_coverage_drop configured
|
7
8
|
Given SimpleCov for Test/Unit is configured with:
|
8
9
|
"""
|
9
10
|
require 'simplecov'
|
@@ -16,6 +17,14 @@ Feature:
|
|
16
17
|
When I run `bundle exec rake test`
|
17
18
|
Then the exit status should be 0
|
18
19
|
And a file named "coverage/.last_run.json" should exist
|
20
|
+
And the file "coverage/.last_run.json" should contain:
|
21
|
+
"""
|
22
|
+
{
|
23
|
+
"result": {
|
24
|
+
"covered_percent": 88.1
|
25
|
+
}
|
26
|
+
}
|
27
|
+
"""
|
19
28
|
|
20
29
|
Given a file named "lib/faked_project/missed.rb" with:
|
21
30
|
"""
|
@@ -32,4 +41,55 @@ Feature:
|
|
32
41
|
Then the exit status should not be 0
|
33
42
|
And the output should contain "Coverage has dropped by 3.32% since the last time (maximum allowed: 0.00%)."
|
34
43
|
And a file named "coverage/.last_run.json" should exist
|
44
|
+
And the file "coverage/.last_run.json" should contain:
|
45
|
+
"""
|
46
|
+
{
|
47
|
+
"result": {
|
48
|
+
"covered_percent": 88.1
|
49
|
+
}
|
50
|
+
}
|
51
|
+
"""
|
52
|
+
|
53
|
+
Scenario: refuse_coverage_drop not configured updates resultset
|
54
|
+
Given SimpleCov for Test/Unit is configured with:
|
55
|
+
"""
|
56
|
+
require 'simplecov'
|
57
|
+
SimpleCov.start do
|
58
|
+
add_filter 'test.rb'
|
59
|
+
end
|
60
|
+
"""
|
61
|
+
|
62
|
+
When I run `bundle exec rake test`
|
63
|
+
Then the exit status should be 0
|
64
|
+
And a file named "coverage/.last_run.json" should exist
|
65
|
+
And the file "coverage/.last_run.json" should contain:
|
66
|
+
"""
|
67
|
+
{
|
68
|
+
"result": {
|
69
|
+
"covered_percent": 88.1
|
70
|
+
}
|
71
|
+
}
|
72
|
+
"""
|
35
73
|
|
74
|
+
Given a file named "lib/faked_project/missed.rb" with:
|
75
|
+
"""
|
76
|
+
class UncoveredSourceCode
|
77
|
+
def foo
|
78
|
+
never_reached
|
79
|
+
rescue => err
|
80
|
+
but no one cares about invalid ruby here
|
81
|
+
end
|
82
|
+
end
|
83
|
+
"""
|
84
|
+
|
85
|
+
When I run `bundle exec rake test`
|
86
|
+
Then the exit status should be 0
|
87
|
+
And a file named "coverage/.last_run.json" should exist
|
88
|
+
And the file "coverage/.last_run.json" should contain:
|
89
|
+
"""
|
90
|
+
{
|
91
|
+
"result": {
|
92
|
+
"covered_percent": 84.78
|
93
|
+
}
|
94
|
+
}
|
95
|
+
"""
|
@@ -35,7 +35,7 @@ Feature:
|
|
35
35
|
| lib/faked_project/meta_magic.rb | 100.0 % |
|
36
36
|
| lib/faked_project/nocov.rb | 100.0 % |
|
37
37
|
|
38
|
-
And there should be
|
38
|
+
And there should be 7 skipped lines in the source files
|
39
39
|
|
40
40
|
And the report should be based upon:
|
41
41
|
| Unit Tests |
|
@@ -64,7 +64,7 @@ Feature:
|
|
64
64
|
| lib/faked_project/meta_magic.rb | 100.0 % |
|
65
65
|
| lib/faked_project/nocov.rb | 100.0 % |
|
66
66
|
|
67
|
-
And there should be
|
67
|
+
And there should be 7 skipped lines in the source files
|
68
68
|
|
69
69
|
And the report should be based upon:
|
70
70
|
| Unit Tests |
|
@@ -61,7 +61,7 @@ Then /^the report should be based upon:$/ do |table|
|
|
61
61
|
)
|
62
62
|
end
|
63
63
|
|
64
|
-
# This is
|
64
|
+
# This is necessary to ensure timing-dependant tests like the merge timeout
|
65
65
|
# do not fail on powerful machines.
|
66
66
|
When /^I wait for (\d+) seconds$/ do |seconds|
|
67
67
|
sleep seconds.to_i
|
data/lib/simplecov.rb
CHANGED
@@ -58,9 +58,9 @@ module SimpleCov
|
|
58
58
|
# their coverage to zero.
|
59
59
|
#
|
60
60
|
def add_not_loaded_files(result)
|
61
|
-
if
|
61
|
+
if tracked_files
|
62
62
|
result = result.dup
|
63
|
-
Dir[
|
63
|
+
Dir[tracked_files].each do |file|
|
64
64
|
absolute = File.expand_path(file)
|
65
65
|
|
66
66
|
result[absolute] ||= [0] * File.foreach(absolute).count
|
@@ -172,7 +172,7 @@ require "simplecov/result"
|
|
172
172
|
require "simplecov/filter"
|
173
173
|
require "simplecov/formatter"
|
174
174
|
require "simplecov/last_run"
|
175
|
-
require "simplecov/
|
175
|
+
require "simplecov/raw_coverage"
|
176
176
|
require "simplecov/result_merger"
|
177
177
|
require "simplecov/command_guesser"
|
178
178
|
require "simplecov/version"
|
@@ -50,9 +50,16 @@ module SimpleCov
|
|
50
50
|
# or not they were explicitly required. Without this, un-required files
|
51
51
|
# will not be present in the final report.
|
52
52
|
#
|
53
|
-
def track_files(glob
|
54
|
-
|
55
|
-
|
53
|
+
def track_files(glob)
|
54
|
+
@tracked_files = glob
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Returns the glob that will be used to include files that were not
|
59
|
+
# explicitly required.
|
60
|
+
#
|
61
|
+
def tracked_files
|
62
|
+
@tracked_files if defined?(@tracked_files)
|
56
63
|
end
|
57
64
|
|
58
65
|
#
|
@@ -143,9 +150,9 @@ module SimpleCov
|
|
143
150
|
# Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
|
144
151
|
# you're calling.
|
145
152
|
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
153
|
+
# SimpleCov.configure do
|
154
|
+
# add_filter 'foobar'
|
155
|
+
# end
|
149
156
|
#
|
150
157
|
# This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure
|
151
158
|
# options at once.
|
@@ -161,10 +168,11 @@ module SimpleCov
|
|
161
168
|
# By default, it will call SimpleCov.result.format!
|
162
169
|
#
|
163
170
|
# Configure with:
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
171
|
+
#
|
172
|
+
# SimpleCov.at_exit do
|
173
|
+
# puts "Coverage done"
|
174
|
+
# SimpleCov.result.format!
|
175
|
+
# end
|
168
176
|
#
|
169
177
|
def at_exit(&block)
|
170
178
|
return proc {} unless running || block_given?
|
@@ -249,15 +257,18 @@ module SimpleCov
|
|
249
257
|
|
250
258
|
#
|
251
259
|
# Add a filter to the processing chain.
|
252
|
-
# There are
|
260
|
+
# There are four ways to define a filter:
|
253
261
|
#
|
254
262
|
# * as a String that will then be matched against all source files' file paths,
|
255
|
-
#
|
263
|
+
# SimpleCov.add_filter 'app/models' # will reject all your models
|
256
264
|
# * as a block which will be passed the source file in question and should either
|
257
265
|
# return a true or false value, depending on whether the file should be removed
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
266
|
+
# SimpleCov.add_filter do |src_file|
|
267
|
+
# File.basename(src_file.filename) == 'environment.rb'
|
268
|
+
# end # Will exclude environment.rb files from the results
|
269
|
+
# * as an array of strings that are matched against all sorce files' file
|
270
|
+
# paths and then ignored (basically string filter multiple times)
|
271
|
+
# SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs
|
261
272
|
# * as an instance of a subclass of SimpleCov::Filter. See the documentation there
|
262
273
|
# on how to define your own filter classes
|
263
274
|
#
|
@@ -277,7 +288,7 @@ module SimpleCov
|
|
277
288
|
private
|
278
289
|
|
279
290
|
#
|
280
|
-
# The
|
291
|
+
# The actual filter processor. Not meant for direct use
|
281
292
|
#
|
282
293
|
def parse_filter(filter_argument = nil, &filter_proc)
|
283
294
|
if filter_argument.is_a?(SimpleCov::Filter)
|
data/lib/simplecov/defaults.rb
CHANGED
@@ -29,6 +29,7 @@ SimpleCov.profiles.define "rails" do
|
|
29
29
|
add_filter "/db/"
|
30
30
|
|
31
31
|
add_group "Controllers", "app/controllers"
|
32
|
+
add_group "Channels", "app/channels" if defined?(ActionCable)
|
32
33
|
add_group "Models", "app/models"
|
33
34
|
add_group "Mailers", "app/mailers"
|
34
35
|
add_group "Helpers", "app/helpers"
|
@@ -78,15 +79,18 @@ at_exit do # rubocop:disable Metrics/BlockLength
|
|
78
79
|
$stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", SimpleCov.result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
|
79
80
|
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
80
81
|
elsif (last_run = SimpleCov::LastRun.read) # rubocop:disable Metrics/BlockNesting
|
81
|
-
|
82
|
-
if
|
83
|
-
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n",
|
82
|
+
coverage_diff = last_run["result"]["covered_percent"] - covered_percent
|
83
|
+
if coverage_diff > SimpleCov.maximum_coverage_drop # rubocop:disable Metrics/BlockNesting
|
84
|
+
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
|
84
85
|
@exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
|
-
|
90
|
+
# Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped
|
91
|
+
unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
92
|
+
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
93
|
+
end
|
90
94
|
end
|
91
95
|
|
92
96
|
# Force exit with stored status (see github issue #5)
|
@@ -95,12 +99,7 @@ at_exit do # rubocop:disable Metrics/BlockLength
|
|
95
99
|
end
|
96
100
|
|
97
101
|
# Autoload config from ~/.simplecov if present
|
98
|
-
require "
|
99
|
-
home_dir = File.expand_path("~") || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
|
100
|
-
if home_dir
|
101
|
-
global_config_path = File.join(home_dir, ".simplecov")
|
102
|
-
load global_config_path if File.exist?(global_config_path)
|
103
|
-
end
|
102
|
+
require "simplecov/load_global_config"
|
104
103
|
|
105
104
|
# Autoload config from .simplecov if present
|
106
105
|
# Recurse upwards until we find .simplecov or reach the root directory
|
data/lib/simplecov/last_run.rb
CHANGED
@@ -0,0 +1,6 @@
|
|
1
|
+
require "etc"
|
2
|
+
home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
|
3
|
+
if home_dir
|
4
|
+
global_config_path = File.join(home_dir, ".simplecov")
|
5
|
+
load global_config_path if File.exist?(global_config_path)
|
6
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SimpleCov
|
2
|
+
module RawCoverage
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Merges multiple Coverage.result hashes
|
6
|
+
def merge_results(*results)
|
7
|
+
results.reduce({}) do |result, merged|
|
8
|
+
merge_resultsets(result, merged)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Merges two Coverage.result hashes
|
13
|
+
def merge_resultsets(result1, result2)
|
14
|
+
(result1.keys | result2.keys).each_with_object({}) do |filename, merged|
|
15
|
+
file1 = result1[filename]
|
16
|
+
file2 = result2[filename]
|
17
|
+
merged[filename] = merge_file_coverage(file1, file2)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def merge_file_coverage(file1, file2)
|
22
|
+
return (file1 || file2).dup unless file1 && file2
|
23
|
+
|
24
|
+
file1.map.with_index do |count1, index|
|
25
|
+
count2 = file2[index]
|
26
|
+
merge_line_coverage(count1, count2)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def merge_line_coverage(count1, count2)
|
31
|
+
sum = count1.to_i + count2.to_i
|
32
|
+
if sum.zero? && (count1.nil? || count2.nil?)
|
33
|
+
nil
|
34
|
+
else
|
35
|
+
sum
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/simplecov/result.rb
CHANGED
@@ -24,7 +24,6 @@ module SimpleCov
|
|
24
24
|
# Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
|
25
25
|
# coverage data)
|
26
26
|
def initialize(original_result)
|
27
|
-
original_result = original_result.dup.extend(SimpleCov::HashMergeHelper) unless original_result.is_a? SimpleCov::HashMergeHelper
|
28
27
|
@original_result = original_result.freeze
|
29
28
|
@files = SimpleCov::FileList.new(original_result.map do |filename, coverage|
|
30
29
|
SimpleCov::SourceFile.new(filename, coverage) if File.file?(filename)
|
@@ -54,20 +54,24 @@ module SimpleCov
|
|
54
54
|
results
|
55
55
|
end
|
56
56
|
|
57
|
+
# Merge two or more SimpleCov::Results into a new one with merged
|
58
|
+
# coverage data and the command_name for the result consisting of a join
|
59
|
+
# on all source result's names
|
60
|
+
def merge_results(*results)
|
61
|
+
merged = SimpleCov::RawCoverage.merge_results(*results.map(&:original_result))
|
62
|
+
result = SimpleCov::Result.new(merged)
|
63
|
+
# Specify the command name
|
64
|
+
result.command_name = results.map(&:command_name).sort.join(", ")
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
57
68
|
#
|
58
69
|
# Gets all SimpleCov::Results from cache, merges them and produces a new
|
59
70
|
# SimpleCov::Result with merged coverage data and the command_name
|
60
71
|
# for the result consisting of a join on all source result's names
|
61
72
|
#
|
62
73
|
def merged_result
|
63
|
-
|
64
|
-
results.each do |result|
|
65
|
-
merged = result.original_result.merge_resultset(merged)
|
66
|
-
end
|
67
|
-
result = SimpleCov::Result.new(merged)
|
68
|
-
# Specify the command name
|
69
|
-
result.command_name = results.map(&:command_name).sort.join(", ")
|
70
|
-
result
|
74
|
+
merge_results(*results)
|
71
75
|
end
|
72
76
|
|
73
77
|
# Saves the given SimpleCov::Result in the resultset cache
|
@@ -91,22 +91,24 @@ module SimpleCov
|
|
91
91
|
# Returns all source lines for this file as instances of SimpleCov::SourceFile::Line,
|
92
92
|
# and thus including coverage data. Aliased as :source_lines
|
93
93
|
def lines
|
94
|
-
|
94
|
+
@lines ||= build_lines
|
95
|
+
end
|
96
|
+
alias source_lines lines
|
95
97
|
|
96
|
-
|
97
|
-
if coverage.size > src.size
|
98
|
-
$stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]"
|
99
|
-
end
|
98
|
+
def build_lines
|
99
|
+
coverage_exceeding_source_warn if coverage.size > src.size
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
src.each_with_index do |src, i|
|
104
|
-
@lines << SimpleCov::SourceFile::Line.new(src, i + 1, coverage[i])
|
101
|
+
lines = src.map.with_index(1) do |src, i|
|
102
|
+
SimpleCov::SourceFile::Line.new(src, i, coverage[i - 1])
|
105
103
|
end
|
106
|
-
|
107
|
-
|
104
|
+
|
105
|
+
process_skipped_lines(lines)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Warning to identify condition from Issue #56
|
109
|
+
def coverage_exceeding_source_warn
|
110
|
+
$stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]"
|
108
111
|
end
|
109
|
-
alias source_lines lines
|
110
112
|
|
111
113
|
# Access SimpleCov::SourceFile::Line source lines by line number
|
112
114
|
def line(number)
|
@@ -115,31 +117,29 @@ module SimpleCov
|
|
115
117
|
|
116
118
|
# The coverage for this file in percent. 0 if the file has no relevant lines
|
117
119
|
def covered_percent
|
118
|
-
return 100.0 if
|
119
|
-
|
120
|
-
if relevant_lines.zero?
|
121
|
-
|
122
|
-
|
123
|
-
Float(covered_lines.count * 100.0 / relevant_lines.to_f)
|
124
|
-
end
|
120
|
+
return 100.0 if no_lines?
|
121
|
+
|
122
|
+
return 0.0 if relevant_lines.zero?
|
123
|
+
|
124
|
+
Float(covered_lines.size * 100.0 / relevant_lines.to_f)
|
125
125
|
end
|
126
126
|
|
127
127
|
def covered_strength
|
128
|
-
return 0.0 if
|
128
|
+
return 0.0 if no_lines?
|
129
129
|
|
130
|
-
lines_strength
|
131
|
-
|
132
|
-
lines_strength += c.coverage if c.coverage
|
133
|
-
end
|
130
|
+
round_float(lines_strength / relevant_lines.to_f, 1)
|
131
|
+
end
|
134
132
|
|
135
|
-
|
133
|
+
def no_lines?
|
134
|
+
lines.length.zero? || lines.length == never_lines.size
|
135
|
+
end
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
137
|
+
def lines_strength
|
138
|
+
lines.map(&:coverage).compact.reduce(:+)
|
139
|
+
end
|
140
|
+
|
141
|
+
def relevant_lines
|
142
|
+
lines.size - never_lines.size - skipped_lines.size
|
143
143
|
end
|
144
144
|
|
145
145
|
# Returns all covered lines as SimpleCov::SourceFile::Line
|
@@ -166,16 +166,18 @@ module SimpleCov
|
|
166
166
|
|
167
167
|
# Returns the number of relevant lines (covered + missed)
|
168
168
|
def lines_of_code
|
169
|
-
covered_lines.
|
169
|
+
covered_lines.size + missed_lines.size
|
170
170
|
end
|
171
171
|
|
172
172
|
# Will go through all source files and mark lines that are wrapped within # :nocov: comment blocks
|
173
173
|
# as skipped.
|
174
|
-
def process_skipped_lines
|
174
|
+
def process_skipped_lines(lines)
|
175
175
|
skipping = false
|
176
|
+
|
176
177
|
lines.each do |line|
|
177
178
|
if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/
|
178
179
|
skipping = !skipping
|
180
|
+
line.skipped!
|
179
181
|
elsif skipping
|
180
182
|
line.skipped!
|
181
183
|
end
|
data/lib/simplecov/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
describe "loading config" do
|
4
|
+
context "without ENV[HOME]" do
|
5
|
+
it "shouldn't raise any errors" do
|
6
|
+
home = ENV.delete("HOME")
|
7
|
+
begin
|
8
|
+
expect { load "simplecov/load_global_config.rb" }.not_to raise_error
|
9
|
+
ensure
|
10
|
+
ENV["HOME"] = home
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
describe SimpleCov::Configuration do
|
4
|
+
let(:config_class) do
|
5
|
+
Class.new do
|
6
|
+
include SimpleCov::Configuration
|
7
|
+
end
|
8
|
+
end
|
9
|
+
let(:config) { config_class.new }
|
10
|
+
|
11
|
+
describe "#tracked_files" do
|
12
|
+
context "when configured" do
|
13
|
+
let(:glob) { "{app,lib}/**/*.rb" }
|
14
|
+
before { config.track_files(glob) }
|
15
|
+
|
16
|
+
it "returns the configured glob" do
|
17
|
+
expect(config.tracked_files).to eq glob
|
18
|
+
end
|
19
|
+
|
20
|
+
context "and configured again with nil" do
|
21
|
+
before { config.track_files(nil) }
|
22
|
+
|
23
|
+
it "returns nil" do
|
24
|
+
expect(config.tracked_files).to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when unconfigured" do
|
30
|
+
it "returns nil" do
|
31
|
+
expect(config.tracked_files).to be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -6,7 +6,7 @@ When /^I write my cukes for the fake project$/ do
|
|
6
6
|
expect(1).to eq(1)
|
7
7
|
end
|
8
8
|
|
9
|
-
Then /^I make all
|
9
|
+
Then /^I make all necessary tests in a single step$/ do
|
10
10
|
expect(FakedProject.foo).to eq("bar")
|
11
11
|
|
12
12
|
expect(FrameworkSpecific.cucumber).to eq("Only tested in Cucumber")
|
data/spec/file_list_spec.rb
CHANGED
@@ -19,16 +19,16 @@ if SimpleCov.usable?
|
|
19
19
|
expect(subject.missed_lines).to eq(3)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "has
|
23
|
-
expect(subject.never_lines).to eq(
|
22
|
+
it "has 17 never lines" do
|
23
|
+
expect(subject.never_lines).to eq(17)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "has 14 lines of code" do
|
27
27
|
expect(subject.lines_of_code).to eq(14)
|
28
28
|
end
|
29
29
|
|
30
|
-
it "has
|
31
|
-
expect(subject.skipped_lines).to eq(
|
30
|
+
it "has 5 skipped lines" do
|
31
|
+
expect(subject.skipped_lines).to eq(5)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "has the correct covered percent" do
|
data/spec/helper.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
if SimpleCov.usable?
|
4
|
+
describe SimpleCov::LastRun do
|
5
|
+
subject { SimpleCov::LastRun }
|
6
|
+
|
7
|
+
it "defines a last_run_path" do
|
8
|
+
expect(subject.last_run_path).to include "tmp/coverage/.last_run.json"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "writes json to its last_run_path that can be parsed again" do
|
12
|
+
structure = [{"key" => "value"}]
|
13
|
+
subject.write(structure)
|
14
|
+
file_contents = File.read(subject.last_run_path)
|
15
|
+
expect(JSON.parse(file_contents)).to eq structure
|
16
|
+
end
|
17
|
+
|
18
|
+
context "reading" do
|
19
|
+
context "but the last_run file does not exist" do
|
20
|
+
before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }
|
21
|
+
|
22
|
+
it "returns nil" do
|
23
|
+
expect(subject.read).to be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "a non empty result" do
|
28
|
+
before { subject.write([]) }
|
29
|
+
|
30
|
+
it "reads json from its last_run_path" do
|
31
|
+
expect(subject.read).to eq([])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "an empty result" do
|
36
|
+
before do
|
37
|
+
File.open(subject.last_run_path, "w+") do |f|
|
38
|
+
f.puts ""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns nil" do
|
43
|
+
expect(subject.read).to be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
if SimpleCov.usable?
|
4
|
+
describe SimpleCov::RawCoverage do
|
5
|
+
describe "with two faked coverage resultsets" do
|
6
|
+
before do
|
7
|
+
@resultset1 = {
|
8
|
+
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
9
|
+
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
10
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
11
|
+
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
12
|
+
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
|
13
|
+
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
|
14
|
+
source_fixture("three.rb") => [nil, 1, 1],
|
15
|
+
}
|
16
|
+
|
17
|
+
@resultset2 = {
|
18
|
+
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
19
|
+
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
20
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
21
|
+
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
|
22
|
+
source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
|
23
|
+
source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
|
24
|
+
source_fixture("three.rb") => [nil, 1, 4],
|
25
|
+
}
|
26
|
+
|
27
|
+
@resultset3 = {
|
28
|
+
source_fixture("three.rb") => [nil, 1, 2],
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
context "a merge" do
|
33
|
+
subject do
|
34
|
+
SimpleCov::RawCoverage.merge_results(@resultset1, @resultset2, @resultset3)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has proper results for sample.rb" do
|
38
|
+
expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has proper results for user.rb" do
|
42
|
+
expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has proper results for sample_controller.rb" do
|
46
|
+
expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has proper results for resultset1.rb" do
|
50
|
+
expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has proper results for resultset2.rb" do
|
54
|
+
expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has proper results for parallel_tests.rb" do
|
58
|
+
expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
|
59
|
+
end
|
60
|
+
|
61
|
+
it "has proper results for conditionally_loaded_1.rb" do
|
62
|
+
expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1])
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has proper results for conditionally_loaded_2.rb" do
|
66
|
+
expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1])
|
67
|
+
end
|
68
|
+
|
69
|
+
it "has proper results for three.rb" do
|
70
|
+
expect(subject[source_fixture("three.rb")]).to eq([nil, 3, 7])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "merges frozen resultsets" do
|
76
|
+
resultset1 = {
|
77
|
+
source_fixture("sample.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil].freeze,
|
78
|
+
source_fixture("app/models/user.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil].freeze,
|
79
|
+
}.freeze
|
80
|
+
|
81
|
+
resultset2 = {
|
82
|
+
source_fixture("sample.rb").freeze => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil].freeze,
|
83
|
+
}.freeze
|
84
|
+
|
85
|
+
merged_result = SimpleCov::RawCoverage.merge_results(resultset1, resultset2)
|
86
|
+
expect(merged_result.keys).to eq(resultset1.keys)
|
87
|
+
expect(merged_result.values.map(&:frozen?)).to eq([false, false])
|
88
|
+
expect(merged_result[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
89
|
+
expect(merged_result[source_fixture("app/models/user.rb")]).to eq([nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
if SimpleCov.usable?
|
4
|
-
describe
|
4
|
+
describe SimpleCov::ResultMerger do
|
5
5
|
describe "with two faked coverage resultsets" do
|
6
6
|
before do
|
7
7
|
SimpleCov.use_merging true
|
@@ -12,7 +12,7 @@ if SimpleCov.usable?
|
|
12
12
|
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
13
13
|
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
|
14
14
|
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
|
15
|
-
}
|
15
|
+
}
|
16
16
|
|
17
17
|
@resultset2 = {
|
18
18
|
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
@@ -24,44 +24,6 @@ if SimpleCov.usable?
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
-
context "a merge" do
|
28
|
-
subject do
|
29
|
-
@resultset1.merge_resultset(@resultset2)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has proper results for sample.rb" do
|
33
|
-
expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
34
|
-
end
|
35
|
-
|
36
|
-
it "has proper results for user.rb" do
|
37
|
-
expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has proper results for sample_controller.rb" do
|
41
|
-
expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
|
42
|
-
end
|
43
|
-
|
44
|
-
it "has proper results for resultset1.rb" do
|
45
|
-
expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
|
46
|
-
end
|
47
|
-
|
48
|
-
it "has proper results for resultset2.rb" do
|
49
|
-
expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
|
50
|
-
end
|
51
|
-
|
52
|
-
it "has proper results for parallel_tests.rb" do
|
53
|
-
expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
|
54
|
-
end
|
55
|
-
|
56
|
-
it "has proper results for conditionally_loaded_1.rb" do
|
57
|
-
expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1])
|
58
|
-
end
|
59
|
-
|
60
|
-
it "has proper results for conditionally_loaded_2.rb" do
|
61
|
-
expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
27
|
# See Github issue #6
|
66
28
|
it "returns an empty hash when the resultset cache file is empty" do
|
67
29
|
File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
|
data/spec/source_file_spec.rb
CHANGED
@@ -42,12 +42,12 @@ if SimpleCov.usable?
|
|
42
42
|
expect(subject.missed_lines.map(&:line)).to eq([8])
|
43
43
|
end
|
44
44
|
|
45
|
-
it "returns lines number 1, 5, 6, 9, 10,
|
46
|
-
expect(subject.never_lines.map(&:line)).to eq([1, 5, 6, 9, 10,
|
45
|
+
it "returns lines number 1, 5, 6, 9, 10, 16 for never_lines" do
|
46
|
+
expect(subject.never_lines.map(&:line)).to eq([1, 5, 6, 9, 10, 16])
|
47
47
|
end
|
48
48
|
|
49
|
-
it "returns line numbers 12, 13, 14 for skipped_lines" do
|
50
|
-
expect(subject.skipped_lines.map(&:line)).to eq([12, 13, 14])
|
49
|
+
it "returns line numbers 11, 12, 13, 14, 15 for skipped_lines" do
|
50
|
+
expect(subject.skipped_lines.map(&:line)).to eq([11, 12, 13, 14, 15])
|
51
51
|
end
|
52
52
|
|
53
53
|
it "has 80% covered_percent" do
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Borrowed and heavily adjusted from:
|
2
|
+
# https://github.com/metricfu/metric_fu/blob/master/spec/capture_warnings.rb
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
class FailOnWarnings
|
6
|
+
def initialize
|
7
|
+
@stderr_stream = StringIO.new
|
8
|
+
@app_root = Dir.pwd
|
9
|
+
end
|
10
|
+
|
11
|
+
def collect_warnings
|
12
|
+
$stderr = @stderr_stream
|
13
|
+
$VERBOSE = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_warnings
|
17
|
+
lines = close_stream
|
18
|
+
app_warnings, other_warnings = split_lines(lines)
|
19
|
+
|
20
|
+
print_own_warnings(app_warnings) if app_warnings.any?
|
21
|
+
write_other_warnings_to_tmp(other_warnings) if other_warnings.any?
|
22
|
+
fail_script(app_warnings) if app_warnings.any?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def close_stream
|
28
|
+
$stderr = STDERR
|
29
|
+
|
30
|
+
@stderr_stream.rewind
|
31
|
+
lines = @stderr_stream.read.split("\n")
|
32
|
+
lines.uniq!
|
33
|
+
@stderr_stream.close
|
34
|
+
lines
|
35
|
+
end
|
36
|
+
|
37
|
+
def split_lines(lines)
|
38
|
+
lines.partition { |line| line.include?(@app_root) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def print_own_warnings(app_warnings)
|
42
|
+
puts ""
|
43
|
+
puts ""
|
44
|
+
puts <<-WARNINGS
|
45
|
+
#{'-' * 30} app warnings: #{'-' * 30}
|
46
|
+
#{app_warnings.join("\n")}
|
47
|
+
#{'-' * 75}
|
48
|
+
WARNINGS
|
49
|
+
end
|
50
|
+
|
51
|
+
def write_other_warnings_to_tmp(other_warnings)
|
52
|
+
output_dir = File.join(@app_root, "tmp")
|
53
|
+
FileUtils.mkdir_p(output_dir)
|
54
|
+
output_file = File.join(output_dir, "warnings.txt")
|
55
|
+
File.open(output_file, "w") do |file|
|
56
|
+
file.write(other_warnings.join("\n") << "\n")
|
57
|
+
end
|
58
|
+
puts
|
59
|
+
puts "Non-app warnings written to tmp/warnings.txt"
|
60
|
+
puts
|
61
|
+
end
|
62
|
+
|
63
|
+
def fail_script(app_warnings)
|
64
|
+
abort "Failing build due to app warnings: #{app_warnings.inspect}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
warning_collector = FailOnWarnings.new
|
69
|
+
warning_collector.collect_warnings
|
70
|
+
|
71
|
+
RSpec.configure do |config|
|
72
|
+
config.after(:suite) do
|
73
|
+
warning_collector.process_warnings
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Olszowka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -141,11 +141,12 @@ files:
|
|
141
141
|
- lib/simplecov/formatter/simple_formatter.rb
|
142
142
|
- lib/simplecov/jruby_fix.rb
|
143
143
|
- lib/simplecov/last_run.rb
|
144
|
-
- lib/simplecov/
|
144
|
+
- lib/simplecov/load_global_config.rb
|
145
145
|
- lib/simplecov/no_defaults.rb
|
146
146
|
- lib/simplecov/profiles.rb
|
147
147
|
- lib/simplecov/railtie.rb
|
148
148
|
- lib/simplecov/railties/tasks.rake
|
149
|
+
- lib/simplecov/raw_coverage.rb
|
149
150
|
- lib/simplecov/result.rb
|
150
151
|
- lib/simplecov/result_merger.rb
|
151
152
|
- lib/simplecov/source_file.rb
|
@@ -153,6 +154,8 @@ files:
|
|
153
154
|
- simplecov.gemspec
|
154
155
|
- spec/1_8_fallbacks_spec.rb
|
155
156
|
- spec/command_guesser_spec.rb
|
157
|
+
- spec/config_loader_spec.rb
|
158
|
+
- spec/configuration_spec.rb
|
156
159
|
- spec/deleted_source_spec.rb
|
157
160
|
- spec/faked_project/Gemfile
|
158
161
|
- spec/faked_project/Rakefile
|
@@ -189,12 +192,15 @@ files:
|
|
189
192
|
- spec/fixtures/sample.rb
|
190
193
|
- spec/fixtures/utf-8.rb
|
191
194
|
- spec/helper.rb
|
192
|
-
- spec/
|
195
|
+
- spec/last_run_spec.rb
|
193
196
|
- spec/multi_formatter_spec.rb
|
197
|
+
- spec/raw_coverage_spec.rb
|
198
|
+
- spec/result_merger_spec.rb
|
194
199
|
- spec/result_spec.rb
|
195
200
|
- spec/return_codes_spec.rb
|
196
201
|
- spec/source_file_line_spec.rb
|
197
202
|
- spec/source_file_spec.rb
|
203
|
+
- spec/support/fail_rspec_on_ruby_warning.rb
|
198
204
|
homepage: http://github.com/colszowka/simplecov
|
199
205
|
licenses:
|
200
206
|
- MIT
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module SimpleCov
|
2
|
-
module ArrayMergeHelper
|
3
|
-
# Merges an array of coverage results with self
|
4
|
-
def merge_resultset(array)
|
5
|
-
new_array = dup
|
6
|
-
array.each_with_index do |element, i|
|
7
|
-
pair = [element, new_array[i]]
|
8
|
-
new_array[i] = if pair.any?(&:nil?) && pair.map(&:to_i).all?(&:zero?)
|
9
|
-
nil
|
10
|
-
else
|
11
|
-
element.to_i + new_array[i].to_i
|
12
|
-
end
|
13
|
-
end
|
14
|
-
new_array
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module SimpleCov
|
20
|
-
module HashMergeHelper
|
21
|
-
# Merges the given Coverage.result hash with self
|
22
|
-
def merge_resultset(hash)
|
23
|
-
new_resultset = {}
|
24
|
-
(keys + hash.keys).each do |filename|
|
25
|
-
new_resultset[filename] = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
new_resultset.each_key do |filename|
|
29
|
-
result1 = self[filename]
|
30
|
-
result2 = hash[filename]
|
31
|
-
new_resultset[filename] =
|
32
|
-
result1 && result2 ? result1.extend(ArrayMergeHelper).merge_resultset(result2) : (result1 || result2).dup
|
33
|
-
end
|
34
|
-
new_resultset
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|