blob: 81d9f79b07d3cd989ca3068fd231e098723931f3 (
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
|
# taken from facter source code
# ASL 2.0
dir = File.expand_path(File.dirname(__FILE__))
SPECDIR = dir
$LOAD_PATH.unshift("#{dir}/../lib")
require 'mocha'
require 'rspec'
require 'facter'
require 'fileutils'
RSpec.configure do |config|
config.mock_with :mocha
config.before :each do
# Ensure that we don't accidentally cache facts and environment
# between test cases.
Facter::Util::Loader.any_instance.stubs(:load_all)
Facter.clear
Facter.clear_messages
# Store any environment variables away to be restored later
@old_env = {}
ENV.each_key {|k| @old_env[k] = ENV[k]}
end
config.after :each do
# Restore environment variables after execution of each test
@old_env.each_pair {|k, v| ENV[k] = v}
to_remove = ENV.keys.reject {|key| @old_env.include? key }
to_remove.each {|key| ENV.delete key }
end
end
|