From 4ae3e45af78d230b4a046ada8480e9a7ae2cd3e3 Mon Sep 17 00:00:00 2001 From: Ilya Margolin Date: Tue, 31 Jul 2012 16:00:23 +0200 Subject: [PATCH] Cache the result of build_catalog --- lib/rspec-puppet/support.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rspec-puppet/support.rb b/lib/rspec-puppet/support.rb index 452cdca..b6287ff 100644 --- a/lib/rspec-puppet/support.rb +++ b/lib/rspec-puppet/support.rb @@ -1,6 +1,10 @@ module RSpec::Puppet module Support - def build_catalog nodename, facts_val + + @@cache = {} + + protected + def build_catalog_without_cache nodename, facts_val node_obj = Puppet::Node.new(nodename) node_obj.merge(facts_val) @@ -13,6 +17,11 @@ module RSpec::Puppet end end + public + def build_catalog *args + @@cache[args] ||= self.build_catalog_without_cache(*args) + end + def munge_facts(facts) output = {} facts.keys.each { |key| output[key.to_s] = facts[key] }