Ruby puppet rspec如何使用undef参数

Ruby puppet rspec如何使用undef参数,ruby,unit-testing,rspec,puppet,Ruby,Unit Testing,Rspec,Puppet,在我的init.pp清单中,我有一个参数: $database_host = 'db.localhost.com', if $database_host == undef { fail('You must specify database_host') } 并对该参数进行简单检查: $database_host = 'db.localhost.com', if $database_host == undef { fail('You must specify database

在我的init.pp清单中,我有一个参数:

$database_host = 'db.localhost.com',
if $database_host == undef {
    fail('You must specify database_host')
}
并对该参数进行简单检查:

$database_host = 'db.localhost.com',
if $database_host == undef {
    fail('You must specify database_host')
}
我还为该参数添加了rspec测试:

context 'db conf require database_host' do
  let :params do {
    :database_auth => 'local',
    :database_host => :undef,
  }
  end
  it { should raise_error(Puppet::Error, /You must specify database_host/) }
end
但出于某种原因,测试结果显示,没有提出任何问题:

 expected Puppet::Error with message matching /You must specify database_host/ but nothing was raised
若我在init.pp中将database_host设置为undef,并从测试中删除这个参数,那个么它就可以工作了。 但是如何将param从init.pp重写为undef呢

$database_host = 'db.localhost.com'

在我的测试中,是否让它工作?

不工作的原因是
fail
函数来自Puppet,而您在Ruby/RSpec中工作。来自rspecpuble的扩展匹配器不了解Puppet函数。至于如何让它工作,我不知道,但您可能已经成功地将Puppet函数模拟为Ruby方法