rspec-circleci-coverage 0.1.1105 → 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 +51 -6
- 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,16 +88,40 @@ 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)
|
|
111
|
+
# Read Dir.pwd (a system call) once per diff, not once per file
|
|
112
|
+
project_root = Dir.pwd
|
|
70
113
|
|
|
71
|
-
after_coverage.
|
|
114
|
+
after_coverage.filter_map do |file, coverage|
|
|
72
115
|
# Skip files outside project scope, spec files, and rspec gem internals
|
|
73
|
-
next unless in_project_scope?(file)
|
|
116
|
+
next unless in_project_scope?(file, project_root)
|
|
74
117
|
next if file.end_with?('_spec.rb')
|
|
75
118
|
|
|
76
119
|
lines = extract_lines(coverage)
|
|
77
120
|
next if lines.nil?
|
|
78
121
|
|
|
79
|
-
before_lines = extract_lines(
|
|
122
|
+
before_lines = extract_lines(before_coverage[file])
|
|
123
|
+
# Skip unchanged files; Array#== runs in C, much faster than the loop below
|
|
124
|
+
next if lines == before_lines
|
|
80
125
|
|
|
81
126
|
# Any line whose count increased means this test executed the file.
|
|
82
127
|
executed = lines.each_with_index.any? do |count, index|
|
|
@@ -87,7 +132,7 @@ module RSpec
|
|
|
87
132
|
count > before_count
|
|
88
133
|
end
|
|
89
134
|
|
|
90
|
-
|
|
135
|
+
relative_path(file) if executed
|
|
91
136
|
end
|
|
92
137
|
end
|
|
93
138
|
|
|
@@ -120,10 +165,10 @@ module RSpec
|
|
|
120
165
|
pathname.absolute? ? pathname.relative_path_from(Dir.pwd).to_s : file
|
|
121
166
|
end
|
|
122
167
|
|
|
123
|
-
def in_project_scope?(file)
|
|
168
|
+
def in_project_scope?(file, project_root = Dir.pwd)
|
|
124
169
|
# Check if file is within the project directory
|
|
125
170
|
# Files outside the project (system files, gems, etc.) should be filtered out
|
|
126
|
-
return false unless file.start_with?(
|
|
171
|
+
return false unless file.start_with?(project_root)
|
|
127
172
|
|
|
128
173
|
# Exclude gem files (even if they're in .bundle or vendor directories)
|
|
129
174
|
return false if file.include?('/gems/')
|