root / spec / spec_helper.rb @ 802d80d1
Historique | Voir | Annoter | Télécharger (1,65 ko)
1 | ece9be27 | tr | # frozen_string_literal: true
|
---|---|---|---|
2 | |||
3 | 64134e4e | tr | require 'puppetlabs_spec_helper/module_spec_helper'
|
4 | require 'rspec-puppet-facts'
|
||
5 | |||
6 | require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) |
||
7 | |||
8 | include RspecPuppetFacts
|
||
9 | |||
10 | default_facts = { |
||
11 | puppetversion: Puppet.version, |
||
12 | facterversion: Facter.version, |
||
13 | } |
||
14 | |||
15 | default_fact_files = [ |
||
16 | File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), |
||
17 | File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), |
||
18 | ] |
||
19 | |||
20 | default_fact_files.each do |f|
|
||
21 | next unless File.exist?(f) && File.readable?(f) && File.size?(f) |
||
22 | |||
23 | begin
|
||
24 | default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) |
||
25 | rescue => e
|
||
26 | RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" |
||
27 | end
|
||
28 | end
|
||
29 | |||
30 | ece9be27 | tr | # read default_facts and merge them over what is provided by facterdb
|
31 | default_facts.each do |fact, value|
|
||
32 | add_custom_fact fact, value |
||
33 | end
|
||
34 | |||
35 | 64134e4e | tr | RSpec.configure do |c| |
36 | c.default_facts = default_facts |
||
37 | c.before :each do |
||
38 | # set to strictest setting for testing
|
||
39 | # by default Puppet runs at warning level
|
||
40 | Puppet.settings[:strict] = :warning |
||
41 | ece9be27 | tr | Puppet.settings[:strict_variables] = true |
42 | 64134e4e | tr | end
|
43 | c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] |
||
44 | c.after(:suite) do |
||
45 | end
|
||
46 | end
|
||
47 | |||
48 | ece9be27 | tr | # Ensures that a module is defined
|
49 | # @param module_name Name of the module
|
||
50 | 64134e4e | tr | def ensure_module_defined(module_name) |
51 | module_name.split('::').reduce(Object) do |last_module, next_module| |
||
52 | last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) |
||
53 | last_module.const_get(next_module, false)
|
||
54 | end
|
||
55 | end
|
||
56 | |||
57 | # 'spec_overrides' from sync.yml will appear below this line |