rspec-cover_it 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -1
- data/lib/rspec/cover_it/context_coverage.rb +21 -5
- data/lib/rspec/cover_it/coverage_state.rb +1 -1
- 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: 7646cf84b3b24df43ca171de7628e65347bbdc8270dd4ff1de2c3bdc6d44596f
|
4
|
+
data.tar.gz: 47e86f853552fadfa9f64a478871fad62db530e4840d8887a6513593a6505032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 114cb6e33e6867b1c4e4dadc43690e67feeb01cbcdab39bcd24d3d563e65323e43eb09dd2d78f8c5056f1b27faad3ba0f9383a31b5fb216674c92998dc718258
|
7
|
+
data.tar.gz: d89f76882f68ffbf6978407fa6f588e29fa87cf66f6cd64bc985af9510232168204d81925975f739e9cf2961e345b871a45c7ac8894e75f0ea0db6855a2d60d1
|
data/README.md
CHANGED
@@ -78,7 +78,30 @@ We use `Object.const_source_location` to find the file that defines the
|
|
78
78
|
means that, if you are reopening the class somewhere else, that coverage won't
|
79
79
|
be checked; if you are including 15 Concerns, and don't intend to write separate
|
80
80
|
specs for them, be sure to list them as `covers:` metadata on the test. Also,
|
81
|
-
shame
|
81
|
+
shame!
|
82
|
+
|
83
|
+
## Output
|
84
|
+
|
85
|
+
When there's missing coverage on the class under test, you'll currently see
|
86
|
+
output like this:
|
87
|
+
|
88
|
+
```
|
89
|
+
❯ rspec
|
90
|
+
|
91
|
+
Randomized with seed 29392
|
92
|
+
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
93
|
+
An error occurred in an `after(:context)` hook.
|
94
|
+
Failure/Error: fail(MissingCoverage, message)
|
95
|
+
Missing coverage in /Users/emueller/src/quiet_quality/lib/quiet_quality/message.rb on line 7
|
96
|
+
# /Users/emueller/src/rspec-cover_it/lib/rspec/cover_it/context_coverage.rb:40:in `enforce!'
|
97
|
+
# /Users/emueller/src/rspec-cover_it/lib/rspec/cover_it/coverage_state.rb:37:in `block in finish_tracking_for'
|
98
|
+
# /Users/emueller/src/rspec-cover_it/lib/rspec/cover_it/coverage_state.rb:35:in `finish_tracking_for'
|
99
|
+
# /Users/emueller/src/rspec-cover_it/lib/rspec/cover_it.rb:26:in `block (2 levels) in setup'
|
100
|
+
.....................................................................................................................................................................................................................................................................................................
|
101
|
+
|
102
|
+
Finished in 1.06 seconds (files took 0.28925 seconds to load)
|
103
|
+
852 examples, 0 failures, 1 error occurred outside of examples
|
104
|
+
```
|
82
105
|
|
83
106
|
## Drawbacks and Shortcomings
|
84
107
|
|
@@ -8,6 +8,10 @@ module RSpec
|
|
8
8
|
|
9
9
|
attr_accessor :precontext_coverage, :postcontext_coverage
|
10
10
|
|
11
|
+
def pretest_coverage
|
12
|
+
@_pretest_coverage ||= pretest_results[target_path]
|
13
|
+
end
|
14
|
+
|
11
15
|
def local_coverage
|
12
16
|
return nil unless precontext_coverage && postcontext_coverage
|
13
17
|
@_local_coverage ||= pretest_coverage
|
@@ -20,18 +24,30 @@ module RSpec
|
|
20
24
|
covered_line_count.to_f / coverable_line_count.to_f
|
21
25
|
end
|
22
26
|
|
27
|
+
def enforce!
|
28
|
+
return if local_coverage_rate >= 1.0
|
29
|
+
lines = local_coverage.each_with_index.select { |v, _i| v&.zero? }.map(&:last)
|
30
|
+
|
31
|
+
summary =
|
32
|
+
if lines.length == 1
|
33
|
+
"on line #{lines.first}"
|
34
|
+
elsif lines.length <= 10
|
35
|
+
"on lines #{lines.map(&:to_s).join(", ")}"
|
36
|
+
else
|
37
|
+
"on #{lines.length} lines, including #{lines.first(10).map(&:to_s).join(", ")}"
|
38
|
+
end
|
39
|
+
message = "Missing coverage in #{context.target_path} #{summary}"
|
40
|
+
fail(MissingCoverage, message)
|
41
|
+
end
|
42
|
+
|
23
43
|
private
|
24
44
|
|
25
|
-
attr_reader :context, :pretest_results
|
45
|
+
attr_reader :context, :pretest_results
|
26
46
|
|
27
47
|
def target_path
|
28
48
|
@_target_path ||= context.target_path
|
29
49
|
end
|
30
50
|
|
31
|
-
def pretest_coverage
|
32
|
-
@_pretest_coverage ||= pretest_results[target_path]
|
33
|
-
end
|
34
|
-
|
35
51
|
# Really, we shouldn't see nil for any of these values unless they are all
|
36
52
|
# nil. We want the coverage we'd expect to have seen if we ran _just_ this
|
37
53
|
# groups of examples, which ought boe the pretest coverage, plus the
|
@@ -34,7 +34,7 @@ module RSpec
|
|
34
34
|
|
35
35
|
context_coverage_for(context).tap do |context_coverage|
|
36
36
|
context_coverage.postcontext_coverage = Coverage.peek_result[context.target_path]
|
37
|
-
|
37
|
+
context_coverage.enforce!
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|