summaryrefslogtreecommitdiff
path: root/spec/spec_helper_acceptance.rb
blob: 03ff993ca6209a56e12edde6e9841cb668f05189 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env ruby -S rspec
require 'beaker-rspec'
require 'beaker/puppet_install_helper'

UNSUPPORTED_PLATFORMS = []

run_puppet_install_helper

RSpec.configure do |c|
  # Project root
  proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

  # Readable test descriptions
  c.formatter = :documentation

  # Configure all nodes in nodeset
  c.before :suite do
    if ENV['FUTURE_PARSER'] == 'yes'
      default[:default_apply_opts] ||= {}
      default[:default_apply_opts].merge!({:parser => 'future'})
    end

    copy_root_module_to(default, :source => proj_root, :module_name => 'stdlib')
  end
end

def is_future_parser_enabled?
  if default[:type] == 'aio'
    return true
  elsif default[:default_apply_opts]
    return default[:default_apply_opts][:parser] == 'future'
  end
  return false
end

RSpec.shared_context "with faked facts" do
  let(:facts_d) do
    puppet_version = (on default, puppet('--version')).output.chomp
    if Puppet::Util::Package.versioncmp(puppet_version, '4.0.0') < 0 && fact('is_pe', '--puppet') == "true"
      if fact('osfamily') =~ /windows/i
        if fact('kernelmajversion').to_f < 6.0
          'C:/Documents and Settings/All Users/Application Data/PuppetLabs/facter/facts.d'
        else
          'C:/ProgramData/PuppetLabs/facter/facts.d'
        end
      else
        '/etc/puppetlabs/facter/facts.d'
      end
    else
      '/etc/facter/facts.d'
    end
  end

  before :each do
    #No need to create on windows, PE creates by default
    if fact('osfamily') !~ /windows/i
      shell("mkdir -p '#{facts_d}'")
    end
  end

  after :each do
    shell("rm -f '#{facts_d}/fqdn.txt'")
  end

  def fake_fact(name, value)
    shell("echo #{name}=#{value} > '#{facts_d}/#{name}.txt'")
  end
end