2014-02-10 2 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 

그리고 그것은 내 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 
테스트를 실행 할 때 오류 출력을했다

include_recipe 'build-essential::default' 

내 제조법

나는 무엇이 문제인지 모르겠다. 나는 Berkshelf가 cookbooks 의존성을 해결할 수 있다고 생각했다.

+0

것은뿐만 아니라 당신의 spec_helper를 작성하세요 – sethvargo

답변

6

당신이 스택 트레이스를 보면 :

당신은 빌드 - 필수 요리 책은 현재 노드의 플랫폼 제품군에 해당하는 레시피를로드하려고 라인 21에 볼 수
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 

. 그러나 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

관련 문제