Mocking a Template Helper Method


#1

Hey Folks,
For some reason I can’t figure out how to mock a method in chefspec that we
are using in a Template Helper. We have the helper defined in a library
module (1). I’ve done some mocks in the past for other library methods,
however for some reason I can’t seem to figure out the right way to get
this to work for the template helper. Everything I’ve tried results in the
mocked response not coming back.

Does anyone have an example or any docs on how I might pull this off? I’ll
refrain from posting all my failed versions, but this is the one I thought
should work:

::Chef::Mixin::Template::TemplateContext.any_instance.stub(:my_method?).and_return(true)
as well as
allow(::Chef::Mixin::Template::TemplateContext).to
receive(:my_method?).and_return(true)

Thanks

(1) https://docs.getchef.com/resource_template.html#library-modules