X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fspec_helper.rb;h=c6e5525752d9af7efe57713579190c803f4fd88e;hb=3cff22c493a803b407f7dfd4277d33624877c69f;hp=660e21823c075e580de649459aba06d32cc0c998;hpb=5f1cf4a24593b01a04c8886802553c1be2ec48ed;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 660e218..c6e5525 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,74 @@ -require 'rubygems' -require 'puppet' -require 'rspec-puppet' +# frozen_string_literal: true -def param_value(subject, type, title, param) - subject.resource(type, title).send(:parameters)[param.to_sym] +RSpec.configure do |c| + c.mock_with :rspec end -Puppet.parse_config -puppet_module_path = Puppet[:modulepath] +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + +include RspecPuppetFacts + +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue StandardError => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end -fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value +end RSpec.configure do |c| - fixture_module_path = File.join(fixture_path, 'modules') - c.module_path = [fixture_module_path, puppet_module_path].join(":") - c.manifest_dir = File.join(fixture_path, 'manifests') + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) + end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end end + +# Ensures that a module is defined +# @param module_name Name of the module +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +# 'spec_overrides' from sync.yml will appear below this line