]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Enable local testing coverage recording
authorDavid Schmitt <david.schmitt@puppet.com>
Mon, 11 Sep 2017 16:50:33 +0000 (17:50 +0100)
committerDavid Schmitt <david.schmitt@puppet.com>
Mon, 11 Sep 2017 16:50:33 +0000 (17:50 +0100)
Gemfile
Rakefile
spec/spec_helper.rb

diff --git a/Gemfile b/Gemfile
index 70a6af7efb8215ae8558c173f3e03b3173f17875..e327d4a8c80c54c29aed8f88a990722a2a52df43 100644 (file)
--- 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"
index d12d85495d735b72ada9cb125a3b9ce13db13561..9cc8313039091a8bce18c485a8558abb35c8dafc 100644 (file)
--- 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
index 22d5d689f4616681ae30d187d834009cebf008e3..8c046d078b9dff302585cd7cb085100dcfe85b85 100644 (file)
@@ -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
+