Skip to content

Instantly share code, notes, and snippets.

@Zhengquan
Forked from hartmantis/spec_helper.rb
Last active July 27, 2016 05:53
Show Gist options
  • Save Zhengquan/1f84d8d6e25d7655d382368dc66c089f to your computer and use it in GitHub Desktop.
Save Zhengquan/1f84d8d6e25d7655d382368dc66c089f to your computer and use it in GitHub Desktop.
ChefSpec stubs for testing a recipe in isolation with new syntax
module IncludeRecipeHelper
def global_stubs
# Don't worry about external cookbook dependencies
allow_any_instance_of(Chef::Cookbook::Metadata).to receive(:depends)
# Test each recipe in isolation, regardless of includes
@included_recipes = []
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?).and_return(false)
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe) do |i|
allow_any_instance_of(Chef::Recipe).to receive(:loaded_recipe?).with(i).and_return(true)
@included_recipes << i
end
allow_any_instance_of(Chef::RunContext).to receive(: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