[chef] Chefspec and user creation


Chronological Thread 
  • From: Leonard Messier < >
  • To:
  • Subject: [chef] Chefspec and user creation
  • Date: Thu, 13 Feb 2014 14:06:19 +0100

Hi there,

I'm using a before block in my spec to stub the result of a data_bag call in my cookbook. 
What I don't get, is what I'm supposed to write in my « it » block to make sure that I wrote the code to create as many users as there are in the data bag. 

In my recipe I will obviously do something like this (from chefspec github page) :

data_bag('users').each do |user|
  data_bag_item('users', user['id'])
end

In my spec I have 

before do
    Chef::EncryptedDataBagItem.stub(:load).with('users', 'svargo').and_return(...)
end

With an entry that corresponds to the user I added to my databag.

But next ? Is the following sufficient :

it 'performs the action' do
    expect(chef_run).to create_user('my-user').with()
end

Where I'm supposed to repeat the object given as a parameter in the stub call ?
Or am I supposed to call the data_bag method in the it block witch will fetch the data stubbed rather
than real data ?

Thanks in advance

--
Léonard Messier



  • [chef] Chefspec and user creation, Leonard Messier, 02/13/2014

Archive powered by MHonArc 2.6.16.

§