I think I have an updated and cleaner solution to this if you want to ensure include_recipe
is called with the right recipe(s), but don't want to load the resources in the included recipe(s):
before(:all) { @included_recipes = [] }
before do
@stubbed_recipes = %w[test_cookbook::included_recipe apt]
@stubbed_recipes.each do |r|
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with(r) do
@included_recipes << r
end
end
end
it 'includes the correct recipes' do
chef_run
expect(@included_recipes).to match_array(@stubbed_recipes)
end
A complete example of this: https://github.com/atheiman/test-cookbook/pull/4