Hi,
Now that I have a simple unit test with ChefSpec in place, I decided to
move forward with a refactoring.
Here is my spec:
recipes/users_spec.rb:
require ‘spec_helper’
describe ‘masterwrap::users’ do
let(:chef_run) do
ChefSpec::ServerRunner.new do |node, server|
server.create_data_bag(
‘users’, {
‘deploy’ => {
“id” => “deploy”,
“groups” => [ “deploy” ],
“shell” => “/bin/bash”
}
}
)
end.converge(described_recipe)
end
it ‘adds deploy user’ do
expect(chef_run).to create_user(‘deploy’)
end
end
Here is my first iteration that got the specs to pass. I know I am not
really using the users data bag stub/mock:
user ‘deploy’
This implementation obviously is not using the data_bag, so here is my
second iteration, which is using Chef’s users cookbook (1.8.0):
include_recipe ‘users’
users_manage ‘deploy’ do
data_bag 'users’
group_name 'deploy’
action :create
end
Now my spec is failing:
.F
Failures:
-
masterwrap::users adds deploy user
Failure/Error: expect(chef_run).to create_user(‘deploy’)
expected “user[deploy]” with action :create to be in Chef run. Other
user resources:./spec/unit/recipes/users_spec.rb:26:in `block (2 levels) in <top
(required)>’
Finished in 3.99 seconds (files took 2.89 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/unit/recipes/users_spec.rb:25 # masterwrap::users adds deploy
user
I am sure it is something simple I am overlooking. I have read and reread
Chef’s documentation for the users cookbook (
https://supermarket.chef.io/cookbooks/users), but nothing is jumping out at
me. Thank you for your help.
Jimmy