X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fspec_helper.rb;h=1f8b6b4bcb859b551fddc87d454b9397e03691a9;hb=d5e81157b553ff9ccd425bc26d285a2829281072;hp=660e21823c075e580de649459aba06d32cc0c998;hpb=64e1bf9a2f90e3546de11bf2a3375bb530e561ea;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 660e218..1f8b6b4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,52 @@ -require 'rubygems' -require 'puppet' -require 'rspec-puppet' - -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')), +] -fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) +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 => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +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 + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) + end end + +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