2015-05-04 85 views
-1

我想寫一個chefspec用於創建jenkins用戶的代碼,如下所示。我如何使用chefspec包含非廚師資源

jenkins_user 'test1' do 
     full_name 'test user' 
     email  '[email protected]' 
     password  'testp' 
    end 

這裏「jenkins_user」不是廚師資源。我如何編寫chefspec來對配方進行單元測試。

或者如果我們有其他方法來運行配方的單元測試,請讓我知道。

+0

您可以閱讀關於[使用ChefSpec測試LWRP]的文檔(https://github.com/sethvargo/chefspec#testing-lwrps) – Tensibai

回答

1

如果包含另一本食譜中定義的資源,如果該食譜作者已編寫libraries/matchers.rb文件,則可以在ChefSpec單元測試中調用這些匹配器。

例如,如果您使用的是Jenkins Community Cookbook,您將看到已有一個matchers.rb文件位於here。所以,你應該能夠創建單元測試是這樣的:

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

如果您包括不具有的匹配定義,那麼你將不得不寫自己的匹配菜譜資源,並做詳細這在Tensibai連接的文件中。