我如何使用chefspec包含非厨师资源

时间:2015-05-04 09:41:26

标签: chef chefspec

我想为其中一个配方创建chefspec,其中包含创建jenkins用户的代码,如下所示。

docker create --name="new_gitlab_data" gitlab_data_image
docker run gitlab --volumes-from=new_gitlab_data 

这里" jenkins_user"不是厨师资源。我如何写一个chefspec来对食谱进行单元测试。

或者如果我们有另一种方法对食谱进行单元测试,请告诉我。

1 个答案:

答案 0 :(得分: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.