(maint) Clear all facts before each example

Without this patch example groups must explicitly call `Facter.clear` to
clear any cached values between examples.  This is a problem because
this behavior is not the concern of the example groups, the behavior is
the concern of the spec_helper or whatever facility we have in place to
initialize the system for testing.

This patch fixes the problem by duplicating the logic in the Facter
spec_helper to ensure facts are cleared out before each example.

This patch requires the example groups to explicitly load the facts they
require if the fact name does not match the filename.
This commit is contained in:
Jeff McCune 2012-10-24 16:59:43 -07:00 committed by Matthaus Owens
parent 4442f1edb5
commit ba70a3885a

View file

@ -12,3 +12,17 @@ require 'rspec/expectations'
require 'puppetlabs_spec_helper/module_spec_helper' require 'puppetlabs_spec_helper/module_spec_helper'
RSpec.configure do |config|
# FIXME REVISIT - We may want to delegate to Facter like we do in
# Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because
# this behavior is a duplication of the spec_helper in Facter.
config.before :each do
# Ensure that we don't accidentally cache facts and environment between
# test cases. This requires each example group to explicitly load the
# facts being exercised with something like
# Facter.collection.loader.load(:ipaddress)
Facter::Util::Loader.any_instance.stubs(:load_all)
Facter.clear
Facter.clear_messages
end
end