rspec-circleci-coverage 0.1.1110 → 0.1.1145
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 +4 -4
- data/lib/rspec/circleci/coverage.rb +44 -3
- 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: ec5359771f874dfe64a11041c2e0fc96ac0f93ea9dc82947e5ed5484e8b145b9
|
|
4
|
+
data.tar.gz: 48b64e6cb655382e26ed8b898750508bf661d070883d1cfead24cf78af19d9ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f87216653e41c7e3cd03a81ad395acfe36f4d140e09975c64f6df6e5d00fcc7895814136d95b91ddd9e42e8318f874442670eacbeb5e225c3a39da9a4900bce8
|
|
7
|
+
data.tar.gz: 71c958607b2a811ae419df88c6c1e2e3e8751f677a444ca72d65ac46986fed8cfd6f2b8d953c58723771bcf962d1058e8ced9c6e96fac4704dc55f554caf9935
|
|
@@ -20,6 +20,10 @@ module RSpec
|
|
|
20
20
|
def initialize
|
|
21
21
|
@coverage_data = Hash.new { |h, k| h[k] = {} }
|
|
22
22
|
@before_coverage = {}
|
|
23
|
+
# Files each example group's before(:context) setup executed
|
|
24
|
+
@group_setup_files = {}
|
|
25
|
+
@setup_group = nil
|
|
26
|
+
@setup_start_coverage = nil
|
|
23
27
|
@installed = false
|
|
24
28
|
end
|
|
25
29
|
|
|
@@ -38,6 +42,9 @@ module RSpec
|
|
|
38
42
|
RSpec.configure do |config|
|
|
39
43
|
config.before(:suite) do
|
|
40
44
|
$stdout.write("rspec-circleci-coverage: generating CircleCI coverage JSON...\n")
|
|
45
|
+
# Notify us as each group starts, nested groups included. Registered here
|
|
46
|
+
# rather than at install so the reporter is built after the formatters
|
|
47
|
+
config.reporter.register_listener(coverage_instance, :example_group_started, :example_started)
|
|
41
48
|
end
|
|
42
49
|
|
|
43
50
|
config.before(:each) do |_|
|
|
@@ -57,6 +64,20 @@ module RSpec
|
|
|
57
64
|
end
|
|
58
65
|
end
|
|
59
66
|
|
|
67
|
+
# Group setup (before(:context), let_it_be) runs outside example snapshots.
|
|
68
|
+
# It lasts from the group's start until its first example or nested group
|
|
69
|
+
# starts, closing before around hooks.
|
|
70
|
+
def example_group_started(notification)
|
|
71
|
+
snapshot = ::Coverage.peek_result
|
|
72
|
+
finish_group_setup(snapshot)
|
|
73
|
+
@setup_group = notification.group
|
|
74
|
+
@setup_start_coverage = snapshot
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def example_started(_notification)
|
|
78
|
+
finish_group_setup(::Coverage.peek_result) if @setup_group
|
|
79
|
+
end
|
|
80
|
+
|
|
60
81
|
def capture_coverage
|
|
61
82
|
@before_coverage = ::Coverage.peek_result.dup
|
|
62
83
|
end
|
|
@@ -67,10 +88,30 @@ module RSpec
|
|
|
67
88
|
|
|
68
89
|
# Calculate which lines were executed during this test
|
|
69
90
|
test_key = format_test_key(example)
|
|
91
|
+
files = executed_files(@before_coverage, after_coverage)
|
|
92
|
+
|
|
93
|
+
# Include the setup of the example's group and every group around it
|
|
94
|
+
example.example_group.ancestors.each do |group|
|
|
95
|
+
files.concat(@group_setup_files.fetch(group, []))
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
files.uniq.each { |file| @coverage_data[file][test_key] = true }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def finish_group_setup(coverage)
|
|
102
|
+
return unless @setup_group
|
|
103
|
+
|
|
104
|
+
files = executed_files(@setup_start_coverage, coverage)
|
|
105
|
+
@group_setup_files[@setup_group] = files unless files.empty?
|
|
106
|
+
@setup_group = nil
|
|
107
|
+
@setup_start_coverage = nil
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def executed_files(before_coverage, after_coverage)
|
|
70
111
|
# Read Dir.pwd (a system call) once per diff, not once per file
|
|
71
112
|
project_root = Dir.pwd
|
|
72
113
|
|
|
73
|
-
after_coverage.
|
|
114
|
+
after_coverage.filter_map do |file, coverage|
|
|
74
115
|
# Skip files outside project scope, spec files, and rspec gem internals
|
|
75
116
|
next unless in_project_scope?(file, project_root)
|
|
76
117
|
next if file.end_with?('_spec.rb')
|
|
@@ -78,7 +119,7 @@ module RSpec
|
|
|
78
119
|
lines = extract_lines(coverage)
|
|
79
120
|
next if lines.nil?
|
|
80
121
|
|
|
81
|
-
before_lines = extract_lines(
|
|
122
|
+
before_lines = extract_lines(before_coverage[file])
|
|
82
123
|
# Skip unchanged files; Array#== runs in C, much faster than the loop below
|
|
83
124
|
next if lines == before_lines
|
|
84
125
|
|
|
@@ -91,7 +132,7 @@ module RSpec
|
|
|
91
132
|
count > before_count
|
|
92
133
|
end
|
|
93
134
|
|
|
94
|
-
|
|
135
|
+
relative_path(file) if executed
|
|
95
136
|
end
|
|
96
137
|
end
|
|
97
138
|
|