rubyrspecchef-infrachefspec

Stub the include_recipe call to take no action but still count the recipe as included


The default recipe for my cookbook simply includes several other recipes. I know that I can test that the appropriate recipes are included using:

expect(chef_run).to include_recipe 'cookbook::recipe_name

but this doesn't work when I've stubbed the include_recipe call like so

Chef::Recipe.any_instance.stub(:include_recipe).with(anything).and_return(true)

I'm stubbing the include_recipe call as I don't want to have to define all the missing attributes for all of my recipes in this spec.

I would have thought that by stubbing the method to return true ChefSpec would report it as having run and consider the recipes included but it doesn't. Any ideas?


Solution

  • I was going to post above as a question but I found a solution posted by 'RoboticCheese' on github so I'm answering my own question as it might help others.

    You do stub include recipe as above but you also need to stub some RunContext methods to count the recipes as having been included.