Unable to stub a library method #273

jperry opened this Issue Dec 10, 2013 · 2 comments


None yet

2 participants

jperry commented Dec 10, 2013


I have looked through the issues but I don't see a specific case like mine for stubbing the library I have created and need a little guidance as I have a feeling Chef is coming in to play here by overwriting my rspec stub.

I have a recipe that has a method

databag = encrypted_data_bag_item('id', 'item')

I have library file in another cookbook that defines this method and then in the recipe I do something like this to make it available to recipes:

::Chef::Recipe.send(:include, Helpers::EncryptedDataBag)

I would like to mock the call to encrypted_data_bag_item and return a hashed result. I have tried several approaches but none seem to work. I'm getting this failure before the mock as well

     Failure/Error: ChefSpec::Runner.new do |node|
       Cannot find a resource for encrypted_data_bag_item on chefspec version 0.6.1

Not sure where the version 0.6.1 is coming from as I am using chefspec 3.0.1

Any help would be much appreciated.


@sethvargo sethvargo closed this Dec 10, 2013
jperry commented Dec 10, 2013

Ah, it was the 'any_instance' message I was missing. Thanks again Seth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment