如何覆盖rspec puppet中的hiera_数据?

如何覆盖rspec puppet中的hiera_数据?,rspec,tdd,puppet,hiera,rspec-puppet,Rspec,Tdd,Puppet,Hiera,Rspec Puppet,假设我有以下测试: context 'test' do let(:hiera_data) { { :number => '2' } } it { should have_module__define_resource_count(2) } end context 'test2' do let(:hiera_data) { { :number => '10' } } it { should have_module__define_resource_count(10

假设我有以下测试:

context 'test' do
  let(:hiera_data) { { :number => '2' } }

  it { should have_module__define_resource_count(2) }
end

context 'test2' do
  let(:hiera_data) { { :number => '10' } }

  it { should have_module__define_resource_count(10) }
end
第一个测试通过,但第二个测试运行时失败,因为hiera变量
number
仍然是2

似乎
let(:hiera_data)
无法重写先前声明的变量

根据这项研究,如果hiera数据设置在不同的文件中,它应该可以工作,但它不工作


我如何在一个specfile中多次测试hiera?

我遇到了同样的问题,有一段时间我被难住了。最终我发现hiera的信息是错误的。您可以这样修复它:

let(:facts) {{ :cache_bust => Time.now }}
例如:

傀儡代码:

class example::bar {
  notify { 'bar': message => hiera('bar_message') }
}
describe "example::bar" do

  let(:facts) {{ :cache_bust => Time.now }}

  describe "first in-line hiera_data test with a" do
    let(:hiera_data) { { :bar_message => "a" } }
    it { should contain_notify("bar").with_message("a") }
  end

  describe "second in-line hiera_data test with b" do
    let(:hiera_data) { { :bar_message => "b" } }
    it { should contain_notify("bar").with_message("b") }
  end
end
rspec伪码:

class example::bar {
  notify { 'bar': message => hiera('bar_message') }
}
describe "example::bar" do

  let(:facts) {{ :cache_bust => Time.now }}

  describe "first in-line hiera_data test with a" do
    let(:hiera_data) { { :bar_message => "a" } }
    it { should contain_notify("bar").with_message("a") }
  end

  describe "second in-line hiera_data test with b" do
    let(:hiera_data) { { :bar_message => "b" } }
    it { should contain_notify("bar").with_message("b") }
  end
end

这管用!botfish fork是hiera puppet helper()最近维护的fork()

您能将完整的测试粘贴到某个地方吗?@FelixFrank问题已更新