-1

i want to write chefspec for one of the recipe which has the code to create jenkins user as shown below.

    jenkins_user 'test1' do
      full_name   'test user'
      email     'test1@test.com'
      password      'testp' 
    end

Here "jenkins_user" is not a chef resource. how do i write a chefspec to run a unit test on the recipe.

or if we have anyother way to run a unit test for the recipe kindly let me know.

Tensibai
  • 15,557
  • 1
  • 37
  • 57
bbsys
  • 33
  • 1
  • 8
  • You may read the docs about [Testing LWRP with ChefSpec](https://github.com/sethvargo/chefspec#testing-lwrps) – Tensibai May 04 '15 at 09:45

1 Answers1

1

When you are including resources that are defined in another cookbook, if the cookbook author has written a libraries/matchers.rb file then you can call those matchers in your ChefSpec unit tests.

For example, if you are using the Jenkins Community Cookbook you will see there is already a matchers.rb file located here. So, you should be able to create unit tests like this:

it 'should create the jenkins user' do
  expect(chef_run).to create_jenkins_user('test1')
end

If you are including resources from a cookbook that does not have matchers defined, then you will have to write your own matchers, and the details for doing this are in the documentation which Tensibai linked to.

Matt Barlow
  • 165
  • 4