I am trying to test a provider in Chef using ChefSpec. In this provider, I am calling another external provider, which I would like to mock/disable, so that only my provider is being executed, not the external provider as well.
My provider is basically this:
action :deploy do
app = new_resource.app
deploy_data = new_resource.deploy_data
opsworks_deploy do
deploy_data deploy_data
app app
end
Chef::Log.debug("This is where the actual code to test is located.")
end
I thought I can mock this somehow by using Chef::Provider::LWRPBase.build_from_file
with an empty provider to supply the external provider mock. While there is apparently a Resource and Provider being generated, it apparently is not registered where it is supposed to be, since the test still complains about the external provider being missing.
Any ideas, hints or examples would be awesome - all examples for provider tests I found are using way simpler and selfcontaining providers, so they do not really help here.
If more context is needed, the provider in question is to be found here: https://github.com/fh/easybib-cookbooks/blob/0a9f7935371d6dc89796e83041cf5092bd96167a/easybib/providers/deploy.rb and the (crappy, nonworking, work in progress verision) of my test is here: https://github.com/fh/easybib-cookbooks/blob/0a9f7935371d6dc89796e83041cf5092bd96167a/easybib/spec/easybib_deploy_spec.rb
edit: Basically, the question here is not how to "overwrite" an existing Provider in my cookbooks with a stub, but how to programmatically create and provide a provider during a ChefSpec run, which does not exist in my cookbooks I am testing.