Révision 78f22811
modulesync 4.0.0
spec/spec_helper.rb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 |
|
|
3 |
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}" |
|
1 |
# This file is managed via modulesync |
|
2 |
# https://github.com/voxpupuli/modulesync |
|
3 |
# https://github.com/voxpupuli/modulesync_config |
|
4 |
|
|
5 |
# puppetlabs_spec_helper will set up coverage if the env variable is set. |
|
6 |
# We want to do this if lib exists and it hasn't been explicitly set. |
|
7 |
ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) |
|
8 |
|
|
9 |
require 'voxpupuli/test/spec_helper' |
|
10 |
|
|
11 |
if File.exist?(File.join(__dir__, 'default_module_facts.yml')) |
|
12 |
facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) |
|
13 |
if facts |
|
14 |
facts.each do |name, value| |
|
15 |
add_custom_fact name.to_sym, value |
|
16 |
end |
|
27 | 17 |
end |
28 | 18 |
end |
29 |
|
|
30 |
# 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 |
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 |
Puppet.settings[:strict_variables] = true |
|
42 |
end |
|
43 |
c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] |
|
44 |
c.after(:suite) do |
|
45 |
end |
|
46 |
end |
|
47 |
|
|
48 |
# Ensures that a module is defined |
|
49 |
# @param module_name Name of the module |
|
50 |
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 |
Formats disponibles : Unified diff