X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fspec_helper.rb;h=16764b6ff147ab99bf87cf2f9a86af7fdb864ac2;hb=2835b79e6f8e517e51e3f1959be34d1d77b5bc15;hp=660e21823c075e580de649459aba06d32cc0c998;hpb=5f1cf4a24593b01a04c8886802553c1be2ec48ed;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 660e218..16764b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,62 @@ -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) -fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# 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 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