spec_helper.rb 1.6 KB
Newer Older
1
require 'puppetlabs_spec_helper/module_spec_helper'
Mickaël Canévet's avatar
Mickaël Canévet committed
2
3
require 'rspec-puppet-facts'
include RspecPuppetFacts
4

5

6
7
8
9
10
11
12
13
RSpec.configure do |c|
  c.include PuppetlabsSpec::Files

  c.before :each do
    # Store any environment variables away to be restored later
    @old_env = {}
    ENV.each_key {|k| @old_env[k] = ENV[k]}

Mickaël Canévet's avatar
Mickaël Canévet committed
14
    Puppet.settings[:strict_variables]=true if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('3.5')
Mickaël Canévet's avatar
Mickaël Canévet committed
15
    Puppet.features.stubs(:root?).returns(true)
16
17
18
19
20
21
  end

  c.after :each do
    PuppetlabsSpec::Files.cleanup
  end
end
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

require 'pathname'
dir = Pathname.new(__FILE__).parent
Puppet[:modulepath] = File.join(dir, 'fixtures', 'modules')

# There's no real need to make this version dependent, but it helps find
# regressions in Puppet
#
# 1. Workaround for issue #16277 where default settings aren't initialised from
# a spec and so the libdir is never initialised (3.0.x)
# 2. Workaround for 2.7.20 that now only loads types for the current node
# environment (#13858) so Puppet[:modulepath] seems to get ignored
# 3. Workaround for 3.5 where context hasn't been configured yet,
# ticket https://tickets.puppetlabs.com/browse/MODULES-823
#
ver = Gem::Version.new(Puppet.version.split('-').first)
38
if Gem::Requirement.new("~> 2.7.20") =~ ver || Gem::Requirement.new("~> 3.0.0") =~ ver || Gem::Requirement.new("~> 3.5") =~ ver || Gem::Requirement.new("~> 4.0")
39
40
41
42
  puts "augeasproviders: setting Puppet[:libdir] to work around broken type autoloading"
  # libdir is only a single dir, so it can only workaround loading of one external module
  Puppet[:libdir] = "#{Puppet[:modulepath]}/augeasproviders_core/lib"
end