Skip to content

Instantly share code, notes, and snippets.

@scalp42
Forked from hartmantis/spec_helper.rb
Created March 14, 2016 21:28
Show Gist options
  • Save scalp42/8cb8f418f4220d7486b6 to your computer and use it in GitHub Desktop.
Save scalp42/8cb8f418f4220d7486b6 to your computer and use it in GitHub Desktop.
ChefSpec stubs for testing a recipe in isolation
require 'chefspec'
module SpecHelper
def global_stubs
# Don't worry about external cookbook dependencies
Chef::Cookbook::Metadata.any_instance.stub(:depends)
# Test each recipe in isolation, regardless of includes
@included_recipes = []
Chef::RunContext.any_instance.stub(:loaded_recipe?).and_return(false)
Chef::Recipe.any_instance.stub(:include_recipe) do |i|
Chef::RunContext.any_instance.stub(:loaded_recipe?).with(i).and_return(true)
@included_recipes << i
end
Chef::RunContext.any_instance.stub(:loaded_recipes).and_return(@included_recipes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment