spec_helper.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. require 'puppetlabs_spec_helper/module_spec_helper'
  2. require 'rspec-puppet-facts'
  3. require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb'))
  4. include RspecPuppetFacts
  5. default_facts = {
  6. puppetversion: Puppet.version,
  7. facterversion: Facter.version,
  8. }
  9. default_fact_files = [
  10. File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')),
  11. File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')),
  12. ]
  13. default_fact_files.each do |f|
  14. next unless File.exist?(f) && File.readable?(f) && File.size?(f)
  15. begin
  16. default_facts.merge!(YAML.safe_load(File.read(f)))
  17. rescue => e
  18. RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}"
  19. end
  20. end
  21. RSpec.configure do |c|
  22. c.default_facts = default_facts
  23. c.before :each do
  24. # set to strictest setting for testing
  25. # by default Puppet runs at warning level
  26. Puppet.settings[:strict] = :warning
  27. end
  28. c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
  29. c.after(:suite) do
  30. end
  31. end
  32. def ensure_module_defined(module_name)
  33. module_name.split('::').reduce(Object) do |last_module, next_module|
  34. last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false)
  35. last_module.const_get(next_module, false)
  36. end
  37. end
  38. # 'spec_overrides' from sync.yml will appear below this line