1

我有一本包含一堆食谱和 LWRP 的食谱。我现在想开始使用 ChefSpec 进行覆盖,并写了一个示例:

require 'chefspec'
require 'chefspec/berkshelf'

ChefSpec::Coverage.start!

RSpec.configure do |config|
  config.platform = 'debian'
  config.version = '7.0'
end

describe 'zilvercms-debian::default' do
  let(:chef_run) { ChefSpec::Runner.new(platform: 'debian', version: '7.0').converge(described_recipe) }

  it 'includes the `timezone-ii::debian` recipe' do
    expect(chef_run).to include_recipe('timezone-ii::debian')
  end
end

我的跑步结果:

~/cookbooks/test-debian$ rspec
[2014-07-21T15:57:58+02:00] WARN: Cloning resource attributes for execute[apt-get-update] from prior resource (CHEF-3694)
[2014-07-21T15:57:58+02:00] WARN: Previous execute[apt-get-update]: /tmp/d20140721-9408-jceoey/cookbooks/apt/recipes/default.rb:29:in `from_file'
[2014-07-21T15:57:58+02:00] WARN: Current  execute[apt-get-update]: /tmp/d20140721-9408-jceoey/cookbooks/apt/recipes/default.rb:38:in `from_file'
.

Finished in 0.16909 seconds (files took 2.29 seconds to load)
1 example, 0 failures

  No Chef resources found, skipping coverage calculation...

有没有人知道为什么 ChefSpec 没有注意到我的资源?


编辑:

按照赛斯的建议搬家ChefSpec::Coverage.start!

这是一个简单的食谱:

# Set timezone for debian machine
include_recipe 'timezone-ii::debian'

# Include recipe for managing repositories on Debian and automatic updating
include_recipe 'debian::default'

# Set NTP for Debian
include_recipe 'ntp::default'
4

1 回答 1

1

根据ChefSpec Reporting 文档,您必须在其他任何内容之前包含覆盖调用:

要生成覆盖率报告,请在您需要任何“Chef”代码之前将以下内容添加到您的 spec_helper.rb 中:

require 'chefspec'
ChefSpec::Coverage.start!

在您的代码中,您在规范已经运行后调用覆盖率报告。移动:

ChefSpec::Coverage.start!

在你的describe块之前。

于 2014-07-21T15:23:54.663 回答