1 # frozen_string_literal: true
7 require 'puppetlabs_spec_helper/module_spec_helper'
8 require 'rspec-puppet-facts'
10 require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb'))
12 include RspecPuppetFacts
15 puppetversion: Puppet.version,
16 facterversion: Facter.version,
19 default_fact_files = [
20 File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')),
21 File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')),
24 default_fact_files.each do |f|
25 next unless File.exist?(f) && File.readable?(f) && File.size?(f)
28 default_facts.merge!(YAML.safe_load(File.read(f), [], [], true))
30 RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}"
34 # read default_facts and merge them over what is provided by facterdb
35 default_facts.each do |fact, value|
36 add_custom_fact fact, value
39 RSpec.configure do |c|
40 c.default_facts = default_facts
42 # set to strictest setting for testing
43 # by default Puppet runs at warning level
44 Puppet.settings[:strict] = :warning
45 Puppet.settings[:strict_variables] = true
47 c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
49 RSpec::Puppet::Coverage.report!(0)
52 # Filter backtrace noise
53 backtrace_exclusion_patterns = [
58 if c.respond_to?(:backtrace_exclusion_patterns)
59 c.backtrace_exclusion_patterns = backtrace_exclusion_patterns
60 elsif c.respond_to?(:backtrace_clean_patterns)
61 c.backtrace_clean_patterns = backtrace_exclusion_patterns
65 # Ensures that a module is defined
66 # @param module_name Name of the module
67 def ensure_module_defined(module_name)
68 module_name.split('::').reduce(Object) do |last_module, next_module|
69 last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false)
70 last_module.const_get(next_module, false)
74 # 'spec_overrides' from sync.yml will appear below this line