Thanks, Daniele. I think you are correct -- I missed that in the README. On Monday, 3 March 2014 11:58:17 UTC-8, Daniele Sluijters wrote: > > Hi, > > First of all, you don't need ", :type => 'class'" since it's in > spec/classes. > > I had a look at the README and the following stood out: > > If you plan to use multiple hiera_config contexts or assign different > values to the hiera_data variable, then you must put the tests in different > files. > > The way I'm interpreting this is that you can only set hiera_data once at > the top just after the opening describe block. Since you're not, every > hiera() function call will do what it's defaults do. Trying to override it > in context's by re-setting hiera_data doesn't work. > > I have no experience whatsoever with hiera-puppet-helper though so I might > be getting this all wrong. > > -- > Daniele Sluijters > > > On Monday, 24 February 2014 17:48:44 UTC+1, Brian Warsing wrote: >> >> 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...<https://github.com/dayglojesus/test-foo> >> >> 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. >> >> *Source for hiera-puppet-helper is: "git:// >> github.com/mmz-srf/hiera-puppet-helper.git" which patches this gem for >> use with Puppet >= 3.4.0 >> >
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/36007850-f8c2-4ed3-82f8-3213431f70d9%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
