diff --git a/lib/rspec-puppet-facts.rb b/lib/rspec-puppet-facts.rb index 661a3d75..ef0a1872 100644 --- a/lib/rspec-puppet-facts.rb +++ b/lib/rspec-puppet-facts.rb @@ -113,14 +113,18 @@ def on_supported_os_implementation(opts = {}) end facterversion_obj = Gem::Version.new(facterversion) + received_facts = [] # FacterDB may have newer versions of facter data for which it contains a subset of all possible # facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to # cycle through and downgrade Facter versions per platform type until we find matching Facter data. filter.each do |filter_spec| - version = FacterDB.get_facts(filter_spec).map { |facts| Gem::Version.new(facts[:facterversion]) }.sort.reverse.detect { |v| v <= facterversion_obj } - next unless version - version = version.to_s + facts = FacterDB.get_facts(filter_spec) + .select { |facts| Gem::Version.new(facts[:facterversion]) <= facterversion_obj } + .max_by { |facts| Gem::Version.new(facts[:facterversion]) } + + next unless facts + version = facts[:facterversion] unless version == facterversion if RspecPuppetFacts.spec_facts_strict? @@ -130,10 +134,9 @@ def on_supported_os_implementation(opts = {}) RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, using v#{version} instead" end - filter_spec[:facterversion] = "/\\A#{Regexp.escape(version)}/" + received_facts << facts end - received_facts = FacterDB::get_facts(filter) unless received_facts.any? RspecPuppetFacts.warning "No facts were found in the FacterDB for: #{filter.inspect}" return {}