【问题标题】:"Cookbook not found" error with ChefSpec testChefSpec 测试出现“未找到食谱”错误
【发布时间】:2014-03-02 09:19:00
【问题描述】:

我正在尝试运行我的 ChefSpec 测试。

这是我的 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 可以解决食谱依赖项。

【问题讨论】:

  • 请同时发布您的 spec_helper

标签: rspec berkshelf chefspec


【解决方案1】:

如果你查看堆栈跟踪:

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 行看到 build-essential cookbook 正在尝试加载与当前节点的平台系列相对应的配方。但是,对于 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) }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 1970-01-01
    • 2016-04-26
    相关资源
    最近更新 更多