(FM-7318) - Added Puppet Strings formatting to documentation
[puppet-modules/puppetlabs-apt.git] / spec / spec_helper.rb
1 require 'puppetlabs_spec_helper/module_spec_helper'
2 require 'rspec-puppet-facts'
3
4 begin
5   require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb'))
6 rescue LoadError => loaderror
7   warn "Could not require spec_helper_local: #{loaderror.message}"
8 end
9
10 include RspecPuppetFacts
11
12 default_facts = {
13   puppetversion: Puppet.version,
14   facterversion: Facter.version,
15 }
16
17 default_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml'))
18 default_module_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml'))
19
20 if File.exist?(default_facts_path) && File.readable?(default_facts_path)
21   default_facts.merge!(YAML.safe_load(File.read(default_facts_path)))
22 end
23
24 if File.exist?(default_module_facts_path) && File.readable?(default_module_facts_path)
25   default_facts.merge!(YAML.safe_load(File.read(default_module_facts_path)))
26 end
27
28 RSpec.configure do |c|
29   c.default_facts = default_facts
30   c.before :each do
31     # set to strictest setting for testing
32     # by default Puppet runs at warning level
33     Puppet.settings[:strict] = :warning
34   end
35 end
36
37 def ensure_module_defined(module_name)
38   module_name.split('::').reduce(Object) do |last_module, next_module|
39     last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module)
40     last_module.const_get(next_module)
41   end
42 end
43
44 # 'spec_overrides' from sync.yml will appear below this line