Permalink
Browse files

Stub out facts properly

Closes #28
  • Loading branch information...
1 parent 0f5321f commit bf2050eee51db8e71f7d158c547fefb8bc1d838e @rodjek committed Jan 24, 2013
Showing with 11 additions and 7 deletions.
  1. +9 −7 lib/rspec-puppet/example/function_example_group.rb
  2. +2 −0 lib/rspec-puppet/support.rb
View
16 lib/rspec-puppet/example/function_example_group.rb
@@ -11,6 +11,15 @@ def subject
Puppet[:modulepath] = self.respond_to?(:module_path) ? module_path : RSpec.configuration.module_path
Puppet[:libdir] = Dir["#{Puppet[:modulepath]}/*/lib"].entries.join(File::PATH_SEPARATOR)
+ nodename = self.respond_to?(:node) ? node : Puppet[:certname]
+ facts_val = {
+ 'hostname' => nodename.split('.').first,
+ 'fqdn' => nodename,
+ 'domain' => nodename.split('.').last,
+ }
+ facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
+ facts_val.each { |k, v| Facter.add(k) { setcode { v } } }
+
# if we specify a pre_condition, we should ensure that we compile that code
# into a catalog that is accessible from the scope where the function is called
if self.respond_to? :pre_condition
@@ -19,13 +28,6 @@ def subject
else
Puppet[:code] = pre_condition
end
- nodename = self.respond_to?(:node) ? node : Puppet[:certname]
- facts_val = {
- 'hostname' => nodename.split('.').first,
- 'fqdn' => nodename,
- 'domain' => nodename.split('.').last,
- }
- facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
# we need to get a compiler, b/c we can attach that to a scope
@compiler = build_compiler(nodename, facts_val)
else
View
2 lib/rspec-puppet/support.rb
@@ -11,6 +11,8 @@ def build_catalog_without_cache(nodename, facts_val, code)
Puppet[:code] = code
+ facts_val.each { |k, v| Facter.add(k) { setcode { v } } }
+
node_obj = Puppet::Node.new(nodename)
node_obj.merge(facts_val)

0 comments on commit bf2050e

Please sign in to comment.