Skip to content

Commit

Permalink
(maint) - update for codecov optional support
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jan 16, 2024
1 parent 8bc53b0 commit d3ce31b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
52 changes: 30 additions & 22 deletions lib/puppetlabs_spec_helper/module_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,43 @@ def verify_contents(subject, title, expected_lines)
module_path = File.join(fixture_path, 'modules')

module_path = [module_path, env_module_path].join(File::PATH_SEPARATOR) if env_module_path

if ENV['SIMPLECOV'] == 'yes'
begin
require 'simplecov'
require 'simplecov-console'

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]

SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'

# do not track gitignored files
# this adds about 4 seconds to the coverage check
# this could definitely be optimized
add_filter do |f|
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
system("git check-ignore --quiet #{f.filename}")
end
end
rescue LoadError
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
end

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]

begin
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
rescue LoadError
# continue without codecov, we could warn here but we wont to avoid if possible
end

SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'

# do not track gitignored files
# this adds about 4 seconds to the coverage check
# this could definitely be optimized
add_filter do |f|
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
system("git check-ignore --quiet #{f.filename}")
end
end
end

# Add all spec lib dirs to LOAD_PATH
Expand Down
35 changes: 21 additions & 14 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
begin
require 'simplecov'
require 'simplecov-console'
rescue LoadError
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
end

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]

SimpleCov.start do
track_files 'lib/**/*.rb'
begin
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
rescue LoadError
# continue without codecov, we could warn here but we wont to avoid if possible
end

add_filter 'lib/puppetlabs_spec_helper/version.rb'
SimpleCov.start do
track_files 'lib/**/*.rb'

add_filter '/spec'
add_filter 'lib/puppetlabs_spec_helper/version.rb'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end
rescue LoadError
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
add_filter '/spec'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end
end

Expand Down

0 comments on commit d3ce31b

Please sign in to comment.