首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在apache_wrapper食谱中运行chefspec时,"Cookbook apache_wrapper not“

在apache_wrapper食谱中运行chefspec时,"Cookbook apache_wrapper not“
EN

Stack Overflow用户
提问于 2014-11-17 15:30:15
回答 1查看 1.1K关注 0票数 1

我是厨师规范方面的新手,我想知道如何在我的烹饪书中使用单元测试。我已经安装了chefdk(v2和v3在不同的ubuntu实例上)和刀规范插件。在"apache_wrapper“烹饪书创建之后,我更改了下一个文件:

spec/spec_helper.rb

代码语言:javascript
复制
require 'chefspec'
require 'chefspec/berkshelf'

RSpec.configure do |config|
config.log_level = :debug
  config.platform = 'ubuntu'
  config.version = '12.04'
end

规范/配方/默认_spec.rb

代码语言:javascript
复制
require_relative '../spec_helper'

describe 'apache_wrapper::default' do
  subject { ChefSpec::Runner.new.converge(described_recipe) }

  it 'includes community cookbook apache2' do
    expect(subject).to include_recipe('apache2')
  end

  it 'creates a template with attributes' do
    expect(subject).to create_template('/var/www/html/index.html').with(
      user:   'root',
      group:  'root',
      backup: true,
    )

    expect(subject).to_not create_template('/var/www/html/index.html').with(
      user:   'bacon',
      group:  'fat',
      backup: true,
    )
  end
end

在我的食谱中,default.eb:

代码语言:javascript
复制
include_recipe 'apache2'

template "/var/www/html/index.html" do
  source "index.html.erb"
  mode 00644
end

但是当我调用rspec时,我得到了下一个:

代码语言:javascript
复制
$ pwd
/tmp/apache_wrapper
$ rspec
...
Failures:

  1) apache_wrapper::default includes community cookbook apache2
     Failure/Error: subject { ChefSpec::Runner.new.converge(described_recipe) }
     Chef::Exceptions::CookbookNotFound:
       Cookbook apache_wrapper not found. If you're loading apache_wrapper from another cookbook, make sure you configure the dependency in your metadata
     # ./spec/recipes/default_spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./spec/recipes/default_spec.rb:27:in `block (2 levels) in <top (required)>'

  2) apache_wrapper::default creates a template with attributes
     Failure/Error: subject { ChefSpec::Runner.new.converge(described_recipe) }
     Chef::Exceptions::CookbookNotFound:
       Cookbook apache_wrapper not found. If you're loading apache_wrapper from another cookbook, make sure you configure the dependency in your metadata
     # ./spec/recipes/default_spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./spec/recipes/default_spec.rb:31:in `block (2 levels) in <top (required)>'

Finished in 0.32355 seconds (files took 2.39 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/recipes/default_spec.rb:26 # apache_wrapper::default includes community cookbook apache2
rspec ./spec/recipes/default_spec.rb:30 # apache_wrapper::default creates a template with attributes

在食谱文件夹中,Berksfile.lock出现了。有人能告诉我我做错了什么吗?

UPD:

Berksfile:

代码语言:javascript
复制
source "https://supermarket.getchef.com"
cookbook 'apache2', '= 1.9.6'

Berksfile.lock

代码语言:javascript
复制
DEPENDENCIES
  apache2 (= 1.9.6)

GRAPH
  apache2 (1.9.6)
    iptables (>= 0.0.0)
    logrotate (>= 0.0.0)
    pacman (>= 0.0.0)
  iptables (0.14.0)
  logrotate (1.7.0)
  pacman (1.1.1)

UPD2:

代码语言:javascript
复制
cat ../apache_wrapper/metadata.rb | grep -E 'dep|nam'
name             'apache_wrapper'
depends 'apache2'

UPD3:

我还试着用next

代码语言:javascript
复制
let (:chef_run) { ChefSpec::ServerRunner.new.converge 'apache_wrapper::default' } 

现在接受

代码语言:javascript
复制
Missing Cookbooks:
------------------
No such cookbook: apache_wrapper

Expanded Run List:
------------------
* apache_wrapper::default

F

Failures:

  1) apache_wrapper::default includes community cookbook apache2
     Failure/Error: let (:chef_run) { ChefSpec::ServerRunner.new.converge 'apache_wrapper::default' }
     Net::HTTPServerException:
       412 "Precondition Failed "
     # ./spec/default_spec.rb:23:in `block (2 levels) in <top (required)>'
     # ./spec/default_spec.rb:26:in `block (2 levels) in <top (required)>

我不明白,我做错了什么,今天我开始了新的安装,在那里安装ruby2.1和所有宝石,如chefspec和其他。现在使用rake运行测试,但仍然会出现相同的错误。

解决方案:只需将“元数据”添加到食谱中

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-18 11:57:36

必须将"apache2“指定为菜谱metadata.rb中的依赖项:

代码语言:javascript
复制
name             'COOKBOOK NAME'
maintainer       'YOUR NAME'
maintainer_email 'YOUR_EMAIL'
...

version          '0.0.1'

depends          'apache2'

在此之后,您可以将"apache2“中的菜谱包含在您的食谱中。

更新:

此外,您还需要指定"apache_wrapper“食谱的位置,请查看chefspec的配置选项以获得更多信息

更新2

metadata添加到您的Berksfile文件中,在此基础上,Berk大陆架将将您的本地菜谱添加到本地菜谱列表中。

来自berkshelf.com:

元数据关键字就像在邦德勒的Gemfile中说出了gemspec。它说,“在我的Berksfile文件的相同相对路径中有一个metadata.rb文件”。这使您可以解决当前正在处理的Cookbook的依赖关系,就像解决当前使用Bundler的Gem的依赖关系一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26976081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档