2014-02-10 60 views
2

我正在嘗試運行我的ChefSpec測試。ChefSpec測試「Cookbook not found」錯誤

這是我ChefSpec測試:

require_relative '../spec_helper' 

describe 'my-demo::basesystem' do 

    let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe)} 

    describe 'basesystem' do 

    it "should be installed" do 
     expect(chef_run).to install_package('build-essential') 
    end 
    end 
end 

而且這是我的食譜

include_recipe 'build-essential::default' 

這是錯誤輸出,當我執行我的ChefSpec測試

================================================================================ 
Recipe Compile Error in /tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb 
================================================================================ 

Chef::Exceptions::CookbookNotFound 
---------------------------------- 
Cookbook build-essential:: not found. If you're loading build-essential:: from another cookbook, make sure you configure the dependency in your metadata 

Cookbook Trace: 
--------------- 
    /tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in `from_file' 
    /tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb:2:in `from_file' 

Relevant File Content: 
---------------------- 
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb: 

14: # distributed under the License is distributed on an "AS IS" BASIS, 
15: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
16: # See the License for the specific language governing permissions and 
17: # limitations under the License. 
18: # 
19: 
20: begin 
21>> include_recipe "build-essential::#{node['platform_family']}" 
22: rescue Chef::Exceptions::RecipeNotFound 
23: Chef::Log.warn "A build-essential recipe does not exist for the platform_family: #{node['platform_family']}" 
24: end 
25: 


Chef::Exceptions::CookbookNotFound: Cookbook build-essential:: not found. If you're loading build-essential:: from another cookbook, make sure you configure the dependency in your metadata 
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in `from_file' 
/tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb:2:in `from_file' 
./spec/recipes/base_system_spec.rb:5:in `block (2 levels) in <top (required)>' 
./spec/recipes/base_system_spec.rb:8:in `block (2 levels) in <top (required)>' 

1 example, 1 failure, 0 passed 

Finished in 0.062297226 seconds 

Process finished with exit code 1 

我不知道是什麼問題,我認爲Berkshelf可以解決cookbooks的依賴關係。

+0

請發表您的spec_helper以及 – sethvargo

回答

6

如果你看一下堆棧跟蹤:

20: begin 
21>> include_recipe "build-essential::#{node['platform_family']}" 
22: rescue Chef::Exceptions::RecipeNotFound 
23: Chef::Log.warn "A build-essential recipe does not exist for the platform_family: #{node['platform_family']}" 
24: end 

你會在第21行的是,建立必要的食譜試圖加載對應於當前節點的平臺系列配方見。但是,對於ChefSpec,除非您特別告訴ChefSpec假冒哪種節點,否則不會設置該數據。換句話說,node['platform_family']nil,所以它試圖包含一個名爲build-essential::(nothing)的配方,這是無效的。

爲了解決這個問題,你可以設定值platform_family:

let(chef_run) do 
    ChefSpec::Runner.new do |node| 
    node.automatic['platform_family'] = 'ubuntu' 
    end.converge(described_recipe) 
end 

或(首選),你可以告訴ChefSpec冒充節點:

let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe) } 
+0

謝謝,像往常一樣,你的答案工作!!!!! – Robert

相關問題