[chef] Re: chefspec and chef-sugar


Chronological Thread 
  • From: Yoshi Spendiff < >
  • To: chef < >
  • Subject: [chef] Re: chefspec and chef-sugar
  • Date: Fri, 7 Aug 2015 11:02:20 -0700

This is the example on the ChefSpec page:

If you are using Encrypted Data Bag Items, you'll need to dive into the RSpec layer and stub that class method instead:

describe 'example::default' do
  before do
    allow(Chef::EncryptedDataBagItem).to receive(:load).with('users', 'svargo').and_return(...)
  end
end
I've not actually done it, but in your case maybe something along these lines?
allow(Chef::EncryptedDataBagItem).to receive(:load).with('ssl', 'dhparam', 'not_nil').and_return(
  'parameters' => 'parameters'
)


On Fri, Aug 7, 2015 at 9:58 AM, Daniel Givens < " target="_blank"> > wrote:

When I test a recipe with chefspec that has 'encrypted_data_bag_item' from chef-sugar, I get an error about the encrypted data bag secret config not being set. I'm not sure how to stub that out.


I don't know ruby much more than what's necessary for chef, so I'm struggling with how to stub that out. This was my attempt:


allow(Chef::Sugar::Databag).to recieve(:encrypted_data_bag_item).with('ssl', 'dhparam', 'not_nil').and_return({
  'parameters' => 'parameters'
})


I get the exception 'uninitialized constant Chef::Sugar'. Any help would be very much appreciated.


Thanks!


Daniel





--
Yoshi Spendiff
Ops Engineer
Indochino
Mobile: +1 778 952 2025



Archive powered by MHonArc 2.6.16.

§