Class: RSpec::Puppet::FacterTestImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-puppet/facter_impl.rb

Overview

Implements a simple hash-based version of Facter to be used in module tests that use rspec-puppet.

Instance Method Summary collapse

Constructor Details

#initializeFacterTestImpl

Returns a new instance of FacterTestImpl.



7
8
9
# File 'lib/rspec-puppet/facter_impl.rb', line 7

def initialize
  @facts = {}
end

Instance Method Details

#add(name, _options = {}, &block) ⇒ Object



25
26
27
28
29
# File 'lib/rspec-puppet/facter_impl.rb', line 25

def add(name, _options = {}, &block)
  raise 'Facter.add expects a block' unless block

  @facts[name.to_s] = instance_eval(&block)
end

#clearObject



17
18
19
# File 'lib/rspec-puppet/facter_impl.rb', line 17

def clear
  @facts.clear
end

#debugging(arg) ⇒ Object

noop methods



32
# File 'lib/rspec-puppet/facter_impl.rb', line 32

def debugging(arg); end

#resetObject



34
# File 'lib/rspec-puppet/facter_impl.rb', line 34

def reset; end

#search(*paths) ⇒ Object



36
# File 'lib/rspec-puppet/facter_impl.rb', line 36

def search(*paths); end

#setup_loggingObject



38
# File 'lib/rspec-puppet/facter_impl.rb', line 38

def setup_logging; end

#to_hashObject



21
22
23
# File 'lib/rspec-puppet/facter_impl.rb', line 21

def to_hash
  @facts
end

#value(fact_name) ⇒ Object



11
12
13
14
15
# File 'lib/rspec-puppet/facter_impl.rb', line 11

def value(fact_name)
  @facts.dig(*fact_name.to_s.split('.'))
rescue TypeError
  nil
end