I have a guard that uses a helper library from one of my cookbook dependencies. When I create a stub for this call I receive the following error during the test run:
uninitialized constant Chef::Acme
Stub:
before(:each) do
allow(Chef::Acme::Helper).to receive(:is_widget_requested?).and_return(true)
end
My dependencies are in my metadata file and I require the 'chefspec/berkshelf' gem in my spec_helper file.
What is the best way to handle this?
After further testing I found a better solution. As so brilliantly stated in 1972 by Butler Lampson:
I created a wrapper in the libraries folder of the cookbook I'm testing which simply calls the original library and then I can stub the library call. This type of abstraction is a common pattern in testing other platforms.
WRAPPER:
Not sure why but the
unless defined?
is required for this to work.TEST: