From: David Schmitt Date: Mon, 11 Sep 2017 16:50:33 +0000 (+0100) Subject: Enable local testing coverage recording X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f3faba87641215642e49db80c0d6fea4dbb9469c;p=puppet-modules%2Fpuppetlabs-apt.git Enable local testing coverage recording --- diff --git a/Gemfile b/Gemfile index 70a6af7..e327d4a 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,10 @@ gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) gem 'facter', *location_for(ENV['FACTER_GEM_VERSION']) if ENV['FACTER_GEM_VERSION'] gem 'hiera', *location_for(ENV['HIERA_GEM_VERSION']) if ENV['HIERA_GEM_VERSION'] -gem 'puppet-resource_api', git: 'https://github.com/puppetlabs/puppet-resource_api', ref: 'master' +gem 'puppet-resource_api', path: '/home/david/git/puppet-resource_api' +# gem 'puppet-resource_api', git: 'https://github.com/puppetlabs/puppet-resource_api', ref: 'master' +gem 'coveralls' +gem 'simplecov-console' # Evaluate Gemfile.local if it exists if File.exists? "#{__FILE__}.local" diff --git a/Rakefile b/Rakefile index d12d854..9cc8313 100644 --- a/Rakefile +++ b/Rakefile @@ -35,3 +35,11 @@ task :gen_nodeset do end puts nodeset end + +namespace :spec do + desc 'Run RSpec code examples with coverage collection' + task :coverage do + ENV['COVERAGE'] = 'yes' + Rake::Task['spec'].execute + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22d5d68..8c046d0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,32 @@ +if ENV['COVERAGE'] == 'yes' + require 'coveralls' + require 'simplecov' + require 'simplecov-console' + + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + # SimpleCov::Formatter::Console, + Coveralls::SimpleCov::Formatter, + ] + 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 + #This file is generated by ModuleSync, do not edit. require 'puppetlabs_spec_helper/module_spec_helper' @@ -6,3 +35,4 @@ begin require 'spec_helper_local' rescue LoadError end +