File: facter_impl.rb

package info (click to toggle)
ruby-rspec-puppet 4.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,444 kB
  • sloc: ruby: 6,377; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 830 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module RSpec::Puppet
  # Implements a simple hash-based version of Facter to be used in module tests
  # that use rspec-puppet.
  class FacterTestImpl
    def initialize
      @facts = {}
    end

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

    def clear
      @facts.clear
    end

    def to_hash
      @facts
    end

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

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

    # noop methods
    def debugging(arg); end

    def reset; end

    def search(*paths); end

    def setup_logging; end

    private

    def setcode(string = nil, &block)
      if block
        yield
      else
        string
      end
    end
  end
end