From 61cd5ae8dbef81228d737658fd738068d96e79df Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 9 Feb 2020 18:38:02 +0100 Subject: [PATCH] Determine correct facter version based on puppet This code comes from modulesync_config: https://github.com/voxpupuli/modulesync_config/commit/666105af193d036d8f150676f8c4704d2abd5e30 --- lib/voxpupuli/test/spec_helper.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/voxpupuli/test/spec_helper.rb b/lib/voxpupuli/test/spec_helper.rb index 2d1ee63..8d94b64 100644 --- a/lib/voxpupuli/test/spec_helper.rb +++ b/lib/voxpupuli/test/spec_helper.rb @@ -4,9 +4,16 @@ # Otherwise we need to match the correct facter version to the used puppet version. # as of 2019-10-31, puppet 5 ships facter 3.11 and puppet 6 ships facter 3.14 # https://puppet.com/docs/puppet/5.5/about_agent.html +# +# The environment variable `PUPPET_VERSION` is available in our travis environment, but we cannot rely on it +# if somebody runs the tests locally. For that case we should fallback the the puppet gem version. def suggest_facter_version - require 'bundler' - Gem::Dependency.new('', ENV['PUPPET_VERSION']).match?('', '5') ? '3.11.0' : '3.14.0' + c.default_facter_version = if ENV['FACTERDB_FACTS_VERSION'] + ENV['FACTERDB_FACTS_VERSION'] + else + puppet_version = ENV['PUPPET_VERSION'] ? ENV['PUPPET_VERSION'] : Gem.loaded_specs['puppet'].version.to_s + Gem::Dependency.new('', puppet_version).match?('', '5') ? '3.11.0' : '3.14.0' + end end RSpec.configure do |config|