Skip to content

Commit

Permalink
(maint) use puppetlabs_spec_helper coverage config
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jun 27, 2019
1 parent 98e859a commit 8348d02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ branches:
matrix:
include:
- rvm: 2.4.3
env: PUPPET_GEM_VERSION='~> 5' COVERAGE=yes # 5.5
- env: RVM="jruby-1.7.26" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug" COVERAGE=yes
env: PUPPET_GEM_VERSION='~> 5' SIMPLECOV=yes # 5.5
- env: RVM="jruby-1.7.26" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug" SIMPLECOV=yes
before_cache: pushd ~/.rvm && rm -rf archives rubies/ruby-2.2.7 rubies/ruby-2.3.4 && popd
cache:
bundler: true
Expand Down Expand Up @@ -45,7 +45,7 @@ matrix:
- rvm: 2.4.1
env: PUPPET_GEM_VERSION='~> 5.0.0'
- rvm: 2.1.9
env: PUPPET_GEM_VERSION='~> 4' COVERAGE=yes # 4.10
env: PUPPET_GEM_VERSION='~> 4' SIMPLECOV=yes # 4.10
- rvm: 2.1.9
env: PUPPET_GEM_VERSION='~> 4.9.0'
- rvm: 2.1.9
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
namespace :spec do
desc 'Run RSpec code examples with coverage collection'
task :coverage do
ENV['COVERAGE'] = 'yes'
ENV['SIMPLECOV'] = 'yes'
Rake::Task['spec'].execute
end
end
Expand Down
37 changes: 5 additions & 32 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
if ENV['COVERAGE'] == 'yes'
require 'simplecov'
require 'simplecov-console'
require 'codecov'

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov,
]
SimpleCov.start do
track_files 'lib/**/*.rb'

add_filter 'lib/puppet/resource_api/version.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

require 'bundler/setup'
require 'puppet/resource_api'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand All @@ -47,4 +15,9 @@
config.mock_with :rspec
end

# load puppet spec support and coverage setup before loading our code
require 'puppetlabs_spec_helper/module_spec_helper'
require 'puppet/resource_api'

# exclude the `version.rb` which already gets loaded by bundler via the gemspec, and doesn't need coverage testing anyways.
SimpleCov.add_filter 'lib/puppet/resource_api/version.rb' if ENV['SIMPLECOV'] == 'yes'

0 comments on commit 8348d02

Please sign in to comment.