Sha256: f71945e14ea004986731b3f30badf4a1099fc69b435e6dcccb94795cf041fd39

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

# Add the projects lib directory to our load path so we can require libraries
# within it easily.
dir = File.expand_path(File.dirname(__FILE__))

SPECDIR = dir
$LOAD_PATH.unshift("#{dir}/../lib")

require 'rubygems'
require 'mocha'
require 'rspec'
require 'facter'
require 'fileutils'
require 'puppetlabs_spec_helper'
require 'pathname'

Pathname.glob("#{dir}/shared_contexts/*.rb") do |file|
  require file.relative_path_from(Pathname.new(dir))
end

RSpec.configure do |config|
  config.mock_with :mocha

  if Facter::Util::Config.is_windows?
    require 'win32console'
    config.output_stream = $stdout
    config.error_stream = $stderr
    config.formatters.each { |f| f.instance_variable_set(:@output, $stdout) }
  end

  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

module FacterSpec
  module ConfigHelper
    def given_a_configuration_of(config)
      Facter::Util::Config.stubs(:is_windows?).returns(config[:is_windows])
      Facter::Util::Config.stubs(:external_facts_dir).returns(config[:external_facts_dir] || "data_dir")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facter-1.7.2 spec/spec_helper.rb
facter-1.7.2.rc1 spec/spec_helper.rb
facter-1.7.1 spec/spec_helper.rb
facter-1.7.1.rc1 spec/spec_helper.rb
facter-1.7.0 spec/spec_helper.rb
facter-1.7.0.rc2 spec/spec_helper.rb