Skip to content

Commit d3ce31b

Browse files
committed
(maint) - update for codecov optional support
1 parent 8bc53b0 commit d3ce31b

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

lib/puppetlabs_spec_helper/module_spec_helper.rb

+30-22
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,43 @@ def verify_contents(subject, title, expected_lines)
2020
module_path = File.join(fixture_path, 'modules')
2121

2222
module_path = [module_path, env_module_path].join(File::PATH_SEPARATOR) if env_module_path
23+
2324
if ENV['SIMPLECOV'] == 'yes'
2425
begin
2526
require 'simplecov'
2627
require 'simplecov-console'
27-
28-
SimpleCov.formatters = [
29-
SimpleCov::Formatter::HTMLFormatter,
30-
SimpleCov::Formatter::Console
31-
]
32-
33-
SimpleCov.start do
34-
track_files 'lib/**/*.rb'
35-
add_filter '/spec'
36-
37-
# do not track vendored files
38-
add_filter '/vendor'
39-
add_filter '/.vendor'
40-
41-
# do not track gitignored files
42-
# this adds about 4 seconds to the coverage check
43-
# this could definitely be optimized
44-
add_filter do |f|
45-
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
46-
system("git check-ignore --quiet #{f.filename}")
47-
end
48-
end
4928
rescue LoadError
5029
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
5130
end
31+
32+
SimpleCov.formatters = [
33+
SimpleCov::Formatter::HTMLFormatter,
34+
SimpleCov::Formatter::Console
35+
]
36+
37+
begin
38+
require 'codecov'
39+
SimpleCov.formatters << SimpleCov::Formatter::Codecov
40+
rescue LoadError
41+
# continue without codecov, we could warn here but we wont to avoid if possible
42+
end
43+
44+
SimpleCov.start do
45+
track_files 'lib/**/*.rb'
46+
add_filter '/spec'
47+
48+
# do not track vendored files
49+
add_filter '/vendor'
50+
add_filter '/.vendor'
51+
52+
# do not track gitignored files
53+
# this adds about 4 seconds to the coverage check
54+
# this could definitely be optimized
55+
add_filter do |f|
56+
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
57+
system("git check-ignore --quiet #{f.filename}")
58+
end
59+
end
5260
end
5361

5462
# Add all spec lib dirs to LOAD_PATH

spec/spec_helper.rb

+21-14
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@
44
begin
55
require 'simplecov'
66
require 'simplecov-console'
7+
rescue LoadError
8+
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
9+
end
710

8-
SimpleCov.formatters = [
9-
SimpleCov::Formatter::HTMLFormatter,
10-
SimpleCov::Formatter::Console
11-
]
11+
SimpleCov.formatters = [
12+
SimpleCov::Formatter::HTMLFormatter,
13+
SimpleCov::Formatter::Console
14+
]
1215

13-
SimpleCov.start do
14-
track_files 'lib/**/*.rb'
16+
begin
17+
require 'codecov'
18+
SimpleCov.formatters << SimpleCov::Formatter::Codecov
19+
rescue LoadError
20+
# continue without codecov, we could warn here but we wont to avoid if possible
21+
end
1522

16-
add_filter 'lib/puppetlabs_spec_helper/version.rb'
23+
SimpleCov.start do
24+
track_files 'lib/**/*.rb'
1725

18-
add_filter '/spec'
26+
add_filter 'lib/puppetlabs_spec_helper/version.rb'
1927

20-
# do not track vendored files
21-
add_filter '/vendor'
22-
add_filter '/.vendor'
23-
end
24-
rescue LoadError
25-
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
28+
add_filter '/spec'
29+
30+
# do not track vendored files
31+
add_filter '/vendor'
32+
add_filter '/.vendor'
2633
end
2734
end
2835

0 commit comments

Comments
 (0)