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 +4 -4
- data/README.md +10 -0
- data/lib/rspec/cover_it/context.rb +7 -3
- data/lib/rspec/cover_it/context_coverage.rb +1 -1
- data/lib/rspec/cover_it/coverage_state.rb +12 -4
- data/lib/rspec/cover_it/pretest_coverage.rb +1 -1
- data/lib/rspec/cover_it/version.rb +1 -1
- data/lib/rspec/cover_it.rb +2 -2
- 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: 66c4b3e0c88dffe53a1d435d40d4e1bdb52038661d8abb89ccc29ef6974398e2
|
4
|
+
data.tar.gz: 563d49e4e8656ea8da53defeb9e2d5f7ed9a91d36e5de0df126213f35dee6813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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
|
@@ -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 =
|
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 =
|
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,
|
data/lib/rspec/cover_it.rb
CHANGED
@@ -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|
|