Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to stub a library method #273

Closed
jperry opened this issue Dec 10, 2013 · 2 comments
Closed

Unable to stub a library method #273

jperry opened this issue Dec 10, 2013 · 2 comments

Comments

@jperry
Copy link

@jperry jperry commented Dec 10, 2013

Hi,

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|
     NameError:
       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.

Thanks,
Jay

@sethvargo
Copy link
Contributor

@sethvargo sethvargo commented Dec 10, 2013

Chef::Recipe.any_instance.stub(:encrypted_data_bag_item).and_return('...')

Loading

@sethvargo sethvargo closed this Dec 10, 2013
@jperry
Copy link
Author

@jperry jperry commented Dec 10, 2013

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

Loading

@lock lock bot locked as resolved and limited conversation to collaborators Aug 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants