module RSpec::Puppet::Consts

Constants

FEATURES
STUBBED_CONSTS

Public Class Methods

restore_consts() click to toggle source
# File lib/rspec-puppet/consts.rb, line 43
def self.restore_consts
  stub_consts_for(RSpec.configuration.platform)
end
stub_const_wrapper(const, value) click to toggle source
# File lib/rspec-puppet/consts.rb, line 36
def self.stub_const_wrapper(const, value)
  klass_name, const_name = const.split('::', 2)
  klass = Object.const_get(klass_name)
  klass.send(:remove_const, const_name) if klass.const_defined?(const_name)
  klass.const_set(const_name, value)
end
stub_consts_for(platform) click to toggle source
# File lib/rspec-puppet/consts.rb, line 26
def self.stub_consts_for(platform)
  STUBBED_CONSTS[platform].each do |const_name, const_value|
    stub_const_wrapper(const_name, const_value)
  end
  Puppet::Util::Platform.pretend_to_be(platform)
  FEATURES[platform].each do |feature_name, feature_value|
    Puppet.features.add(feature_name) { feature_value }
  end
end
without_stubs() { || ... } click to toggle source
# File lib/rspec-puppet/consts.rb, line 47
def self.without_stubs
  if Puppet::Util::Platform.pretending?
    pretend_platform = Puppet::Util::Platform.pretend_platform
    restore_consts
  end

  yield
ensure
  stub_consts_for(pretend_platform) if pretend_platform
end