-
-
Save Zhengquan/1f84d8d6e25d7655d382368dc66c089f to your computer and use it in GitHub Desktop.
ChefSpec stubs for testing a recipe in isolation with new syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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