Mocking an external provider at chefspec

I am trying to test a provider in Chef using ChefSpec. In this provider, I call another external provider that I would like to ridicule / disconnect, so that only my provider is running, not the external provider.

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 could somehow mock it, using Chef::Provider::LWRPBase.build_from_filewith an empty provider to supply an external layout provider. Although the resource and provider are apparently being created, it is apparently not registered where it should be, since the test still complains about the absence of an external provider.

, - , , , .

, : https://github.com/fh/easybib-cookbooks/blob/0a9f7935371d6dc89796e83041cf5092bd96167a/easybib/providers/deploy.rb (, , ) : https://github.com/fh/easybib-cookbooks/blob/0a9f7935371d6dc89796e83041cf5092bd96167a/easybib/spec/easybib_deploy_spec.rb

edit: , , "" , ChefSpec, , .

+4
1

:

let(:my_double) { double('opsworks_deploy') }
Chef::Resource::OpsworksDeploy.stub(:new).and_return(my_double)
0

Source: https://habr.com/ru/post/1532509/


All Articles