Hi,
I hope this on-topic. Let me know if I should post this somewhere more appropriate.
I'm using rspec-puppet, puppetlabs_spec_helper, and a fork of hiera-puppet-helper* while developing a new module for puppet 3.4 and ran into an issue I don't understand.
I have posted a mock-up of the module on Github,
here...
Admittedly, the module uses an unconventional pattern, but I think it should work.
# init.pp
class foo {
$bar_options = is_hash(hiera('foo::bar::options', false))
if $bar_options == true {
contain foo::bar
}
}
# bar.pp
class foo::bar ($options) {
validate_hash($options)
}
Basically, I want to contain the class 'foo::bar' if hiera supplies a hash for 'foo::bar::options'. If not, we simply compile without it.
In my spec for the foo class, I have two contextual tests:
# spec/classes/foo_spec.rb
describe 'foo', :type => 'class' do
context "when there are no BAR options set" do
it { should_not contain_class("foo::bar") }
end
context "when BAR configuration options are set" do
hash = { 'some_key' => "Some Value" }
let :hiera_data do
{
'foo::bar::options' => hash
}
end
it { should contain_class('foo::bar') }
end
end
I would expect that both these tests pass, but the second test always fails.
However, if I remove the first contextual test and just do:
# spec/classes/foo_spec.rb
describe 'foo', :type => 'class' do
context "when BAR configuration options are set" do
hash = { 'some_key' => "Some Value" }
let :hiera_data do
{
'foo::bar::options' => hash
}
end
it { should contain_class('foo::bar') }
end
end
The test passes. And, as you might guess, if I change :hiera_data to something other than a hash, the same test fails:
# spec/classes/foo_spec.rb
describe 'foo', :type => 'class' do
context "when BAR configuration options are set" do
hash = false
let :hiera_data do
{
'foo::bar::options' => hash
}
end
it { should contain_class('foo::bar') }
end
end
# This fails, as it should.
It is only when I test both contexts that ONE of them fails -- the second one always fails.
Is this a bug or am I missing something more fundamental?
Thanks,
--
B.