rspec-cover_it 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 528de4fe406f539d93d8632624714721d8cded1463a35776c16423d387c13c30
4
- data.tar.gz: 57fc958451fb2dfeafb94aaaed56aba38befd938a4ea24d2f82d0ac09a46ee4e
3
+ metadata.gz: 7646cf84b3b24df43ca171de7628e65347bbdc8270dd4ff1de2c3bdc6d44596f
4
+ data.tar.gz: 47e86f853552fadfa9f64a478871fad62db530e4840d8887a6513593a6505032
5
5
  SHA512:
6
- metadata.gz: 6c636b00bd14fd976d53f9f97cbd2d53334ecb5677ad480ef00e737b51144da2f0ae76fffc1f6d1fb0366381961311e8aec93dfe6453cc2942c10dc652d87a88
7
- data.tar.gz: 93c2432a8ce2725b2ca3ff9f1c8115a38154dc7c4426f7aa5667d12ed9546b9890d83885bcbe727064ea78972e58ab4e721b6dcef82d93c004d95f8a8ae6609f
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, :precontext_coverage, :postcontext_coverage
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
- fail("missing coverage!") if context_coverage.local_coverage_rate < 1.0
37
+ context_coverage.enforce!
38
38
  end
39
39
  end
40
40
 
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module CoverIt
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-cover_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Mueller