rspec-cover_it 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7646cf84b3b24df43ca171de7628e65347bbdc8270dd4ff1de2c3bdc6d44596f
4
- data.tar.gz: 47e86f853552fadfa9f64a478871fad62db530e4840d8887a6513593a6505032
3
+ metadata.gz: 66c4b3e0c88dffe53a1d435d40d4e1bdb52038661d8abb89ccc29ef6974398e2
4
+ data.tar.gz: 563d49e4e8656ea8da53defeb9e2d5f7ed9a91d36e5de0df126213f35dee6813
5
5
  SHA512:
6
- metadata.gz: 114cb6e33e6867b1c4e4dadc43690e67feeb01cbcdab39bcd24d3d563e65323e43eb09dd2d78f8c5056f1b27faad3ba0f9383a31b5fb216674c92998dc718258
7
- data.tar.gz: d89f76882f68ffbf6978407fa6f588e29fa87cf66f6cd64bc985af9510232168204d81925975f739e9cf2961e345b871a45c7ac8894e75f0ea0db6855a2d60d1
6
+ metadata.gz: e17ac79db233e4a1f9571f98d025c37cf2e3c304155838fc221507ef5ac6a24aecb47be2f0a6678423009254a0bb5eac442ce775f4ad8bb3f9a66554e9f09fd6
7
+ data.tar.gz: 0c9afcc6b5f019c185365e5c40925a3b96b4108133d1dcc6150edb182780c35e2a946693106fdf9299e507007a1adfb1dc33cbc341b95f729cea1faf202bbab2
data/README.md CHANGED
@@ -126,3 +126,13 @@ aren't a lot of controls - it works, but it's a bit ugly and doesn't really
126
126
  give the right immediate impression. I'm contemplating using an `after(:suite)`
127
127
  hook and aggregating them myself, but at the end of the day RSpec is in control
128
128
  of the output stream, and we don't entirely fit its metaphor.
129
+
130
+ We're using `Object.const_source_location` to find the path of the source file
131
+ defining a given constant. That _mostly_ works, but it actually gives the path
132
+ of the _first_ source file that defined that constant. So if your gem defines
133
+ its version in `lib/foo/version.rb` (as an example), in a separate file from
134
+ lib/foo.rb, the _path_ for `Foo` may end up being the former. Which is.. not
135
+ going to have much coverable code, of course. This is an edge case, but one
136
+ that is likely to occur fairly regularly. I haven't thought of a _good_ solution
137
+ yet. Perhaps if the `covers` array includes a string, we should treat it as a
138
+ relative path?
@@ -1,12 +1,12 @@
1
1
  module RSpec
2
2
  module CoverIt
3
3
  class Context
4
- def initialize(scope:, rspec_context:)
5
- @scope, @rspec_context = scope, rspec_context
4
+ def initialize(scope:, rspec_context:, autoenforce:)
5
+ @scope, @rspec_context, @autoenforce = scope, rspec_context, autoenforce
6
6
  end
7
7
 
8
8
  def cover_it?
9
- target_class && metadata.fetch(:cover_it, nil)
9
+ target_class && metadata.fetch(:cover_it, autoenforce?)
10
10
  end
11
11
 
12
12
  def target_path
@@ -25,6 +25,10 @@ module RSpec
25
25
 
26
26
  attr_reader :scope, :rspec_context
27
27
 
28
+ def autoenforce?
29
+ @autoenforce
30
+ end
31
+
28
32
  def metadata
29
33
  scope.metadata
30
34
  end
@@ -25,7 +25,7 @@ module RSpec
25
25
  end
26
26
 
27
27
  def enforce!
28
- return if local_coverage_rate >= 1.0
28
+ return if local_coverage.nil? || local_coverage_rate >= 1.0
29
29
  lines = local_coverage.each_with_index.select { |v, _i| v&.zero? }.map(&:last)
30
30
 
31
31
  summary =
@@ -3,8 +3,8 @@ module RSpec
3
3
  class CoverageState
4
4
  attr_reader :filter
5
5
 
6
- def initialize(filter:)
7
- @filter = filter
6
+ def initialize(filter: nil, autoenforce: false)
7
+ @filter, @autoenforce = filter, autoenforce
8
8
  @pretest_results = nil
9
9
  @context_coverages = {}
10
10
  end
@@ -20,7 +20,7 @@ module RSpec
20
20
  end
21
21
 
22
22
  def start_tracking_for(scope, rspec_context)
23
- context = Context.new(scope: scope, rspec_context: rspec_context)
23
+ context = context_for(scope, rspec_context)
24
24
  return unless context.cover_it?
25
25
 
26
26
  context_coverage_for(context).tap do |context_coverage|
@@ -29,7 +29,7 @@ module RSpec
29
29
  end
30
30
 
31
31
  def finish_tracking_for(scope, rspec_context)
32
- context = Context.new(scope: scope, rspec_context: rspec_context)
32
+ context = context_for(scope, rspec_context)
33
33
  return unless context.cover_it?
34
34
 
35
35
  context_coverage_for(context).tap do |context_coverage|
@@ -42,6 +42,14 @@ module RSpec
42
42
 
43
43
  attr_reader :pretest_results
44
44
 
45
+ def autoenforce?
46
+ @autoenforce
47
+ end
48
+
49
+ def context_for(scope, rspec_context)
50
+ Context.new(scope: scope, rspec_context: rspec_context, autoenforce: autoenforce?)
51
+ end
52
+
45
53
  def context_coverage_for(context)
46
54
  @context_coverages[context.target_class] ||= ContextCoverage.new(
47
55
  context: context,
@@ -4,7 +4,7 @@ module RSpec
4
4
  def initialize(filter:, results:)
5
5
  @filter = filter
6
6
  @results = results
7
- .select { |k, _v| k.start_with?(filter) }
7
+ .select { |k, _v| filter.nil? || k.start_with?(filter) }
8
8
  .map { |k, v| [k, v.dup] }
9
9
  .to_h
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module CoverIt
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -16,8 +16,8 @@ module RSpec
16
16
  attr_accessor :state
17
17
  end
18
18
 
19
- def self.setup(filter:)
20
- RSpec::CoverIt.state = CoverageState.new(filter: filter)
19
+ def self.setup(filter: nil, autoenforce: false)
20
+ RSpec::CoverIt.state = CoverageState.new(filter: filter, autoenforce: autoenforce)
21
21
  RSpec::CoverIt.state.start_tracking
22
22
 
23
23
  RSpec.configure do |config|
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Mueller