rspec-cover_it 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/rspec/cover_it/context_coverage.rb +5 -2
- data/lib/rspec/cover_it/coverage_state.rb +18 -3
- data/lib/rspec/cover_it/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63e1b79c2f0b0d52869caa48e5d7dcfee100a726f1fb4698bcbef5d228179ec4
|
4
|
+
data.tar.gz: 24d36270a6320b920f30134c8bb354b77325b16e4a311b1fb018470c72f0c5a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f8774a17ea6e1170471182cf768cbd7fc0e3f69a8cf2d04445d7a7ae0e7e04947b6a75205aa2d53eaaeef104597447608b3873413b73bfda2d9b83ce015bec6
|
7
|
+
data.tar.gz: 3cf13d18a7658e6769d672e1d130ace9e3842ce1e3e7edfdf21e3c64753fb47668da6c7fa16690bc78e6741aa58cd03bdf1344d7c98b50a6fdbf51de03ba5ec1
|
data/README.md
CHANGED
@@ -33,10 +33,7 @@ You set up `RSpec::CoverIt` in your `spec_helper.rb` - require `rspec/cover_it`,
|
|
33
33
|
and then `RSpec::CoverIt.setup(**config_options)` (before loading your code, as
|
34
34
|
you would with any other coverage library). It's.. _semi_ compatible with other
|
35
35
|
coverage systems - it only starts Coverage if it's not already running, and it
|
36
|
-
only uses `peek_result`, so it doesn't affect other systems outcomes.
|
37
|
-
setup SimpleCov to do branch-coverage or something, that will break this gem,
|
38
|
-
for now (we assume basic line-coverage style results).
|
39
|
-
|
36
|
+
only uses `peek_result`, so it doesn't affect other systems outcomes.
|
40
37
|
Rough configuration options:
|
41
38
|
|
42
39
|
* `filter`: Only paths starting with this (matching this regex?) can matter
|
@@ -64,6 +61,10 @@ In example groups, you can use metadata to control the behavior of
|
|
64
61
|
the fact that we can't perfectly infer the location of the source code in
|
65
62
|
some cases - in particular, `lib/foo/version.rb` tends to cause a problem
|
66
63
|
for specs on `foo.rb`, since the version file is invariably loaded first.
|
64
|
+
Note - in gems, this _frequently_ also happens when you glob-load a directory
|
65
|
+
_before_ defining the namespace they are all loading objects into. Then the
|
66
|
+
first file in that directory that loads ends up being the one that actually
|
67
|
+
creates the namespace.
|
67
68
|
* `covers`: An array of classes and modules that this example groups _thinks
|
68
69
|
it is completely testing_. Ideally, you'd have a separate test file for each,
|
69
70
|
but sometimes that's hard to do - you can let one spec claim responsibility
|
@@ -57,8 +57,11 @@ module RSpec
|
|
57
57
|
else
|
58
58
|
"on #{lines.length} lines, including #{lines.first(10).map(&:to_s).join(", ")}"
|
59
59
|
end
|
60
|
-
|
61
|
-
fail(MissingCoverage,
|
60
|
+
|
61
|
+
fail(MissingCoverage, <<~MESSAGE.tr("\n", " "))
|
62
|
+
Example group `#{context.scope_name}` is missing coverage on
|
63
|
+
`#{context.target_class}` in `#{context.target_path}` #{summary}
|
64
|
+
MESSAGE
|
62
65
|
end
|
63
66
|
|
64
67
|
attr_reader :context, :pretest_results
|
@@ -16,7 +16,7 @@ module RSpec
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def finish_load_tracking
|
19
|
-
@pretest_results = PretestCoverage.new(filter: filter, results:
|
19
|
+
@pretest_results = PretestCoverage.new(filter: filter, results: get_current_coverage)
|
20
20
|
end
|
21
21
|
|
22
22
|
def start_tracking_for(scope, rspec_context)
|
@@ -24,7 +24,7 @@ module RSpec
|
|
24
24
|
return unless context.cover_it?
|
25
25
|
|
26
26
|
context_coverage_for(context).tap do |context_coverage|
|
27
|
-
context_coverage.precontext_coverage =
|
27
|
+
context_coverage.precontext_coverage = get_current_coverage(context.target_path)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -33,7 +33,7 @@ module RSpec
|
|
33
33
|
return unless context.cover_it?
|
34
34
|
|
35
35
|
context_coverage_for(context).tap do |context_coverage|
|
36
|
-
context_coverage.postcontext_coverage =
|
36
|
+
context_coverage.postcontext_coverage = get_current_coverage(context.target_path)
|
37
37
|
context_coverage.enforce!(default_threshold: default_threshold_rate)
|
38
38
|
end
|
39
39
|
end
|
@@ -60,6 +60,21 @@ module RSpec
|
|
60
60
|
pretest_results: pretest_results
|
61
61
|
)
|
62
62
|
end
|
63
|
+
|
64
|
+
def get_current_coverage(path = nil)
|
65
|
+
result = Coverage.peek_result
|
66
|
+
|
67
|
+
if path
|
68
|
+
value = result[path]
|
69
|
+
value.is_a?(Hash) ? value.fetch(:lines) : value
|
70
|
+
else
|
71
|
+
if result.any? { |_k, v| v.is_a?(Hash) }
|
72
|
+
result.transform_values { |v| v.fetch(:lines) }
|
73
|
+
else
|
74
|
+
result
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
63
78
|
end
|
64
79
|
end
|
65
80
|
end
|