Skip to content

Instantly share code, notes, and snippets.

@ranjib
Last active August 29, 2015 14:12
Show Gist options
  • Save ranjib/c623a611ec634d037610 to your computer and use it in GitHub Desktop.
Save ranjib/c623a611ec634d037610 to your computer and use it in GitHub Desktop.
ChefSpec memoization
let(:runner) do
memoized_runner('pd-gocd::agent') do |node|
#.....
end
end
def clear_runner(recipe)
@@runners.delete recipe
end
def memoized_runner(recipe, options={}, &block)
@@runners[recipe] ||= converged_runner(recipe, options, &block)
end
def converged_runner(recipe, options = {})
runner = ChefSpec::SoloRunner.new(
{file_cache_path: '/var/chef/cache'}.merge(options)
)
yield runner.node if block_given?
runner.converge(recipe)
runner
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment