Module: RSpec::Puppet::Consts

Defined in:
lib/rspec-puppet/consts.rb

Constant Summary collapse

STUBBED_CONSTS =
{
  :posix => {
    'File::PATH_SEPARATOR' => ':',
    'File::ALT_SEPARATOR' => nil,
    'Pathname::SEPARATOR_PAT' => /#{Regexp.quote('/')}/,
  },
  :windows => {
    'File::PATH_SEPARATOR' => ';',
    'File::ALT_SEPARATOR' => "\\",
    'Pathname::SEPARATOR_PAT' => /[#{Regexp.quote("\\")}#{Regexp.quote('/')}]/,
  }
}

Class Method Summary collapse

Class Method Details

.restore_constsObject



28
29
30
# File 'lib/rspec-puppet/consts.rb', line 28

def self.restore_consts
  stub_consts_for(RSpec.configuration.platform)
end

.stub_const_wrapper(const, value) ⇒ Object



21
22
23
24
25
26
# File 'lib/rspec-puppet/consts.rb', line 21

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) ⇒ Object



15
16
17
18
19
# File 'lib/rspec-puppet/consts.rb', line 15

def self.stub_consts_for(platform)
  STUBBED_CONSTS[platform].each do |const_name, const_value|
    stub_const_wrapper(const_name, const_value)
  end
end