Andreas Haerter
2013-Jul-19 22:20 UTC
[Puppet Users] rspec-puppet: how to pass undef as parameter value?
Hi all, is there a way to pass the Puppets undef [1] value as parameter? I got a module with a package_provider parameter, allowing the user two things: 1. specify a specific package provider to use; 2. pass "undef" to let Puppet decide which provider to use instead of the module. Something like:> class example( > $package_provider = $example::params::package_provider, > ) inherits example::params { > > [...] > > package { ''foobar'' > ensure => ''present'', > provider => $package_provider, > } > }Now I want to test if passing undef works:> context ''with parameter(s): package_provider => undef'' do > let(:params) {{ > :package_provider => [WAY-TO-PASS-UNDEF-HERE], > }} > > it ''contains a package with parameter(s): provider => unset'' do > should contain_package(''blueprint'').with({ > ''provider'' => [WAY-TO-CHECK-FOR-UNDEF-HERE, > }) > end > endBut my test doesn''t work. What I tried so far is: 1) undef (results in RSpec/Ruby parsing error)> context ''with parameter(s): foo => undef'' do > let(:params) {{ > :foo => undef, > }} > > [...] > end2) :undef (results in Puppet error: "Syntax error at'':''; expected ''}''" )> context ''with parameter(s): foo => undef'' do > let(:params) {{ > :foo => :undef, > }} > > [...] > end3) nil (does not result in an Puppet or Ruby error, but the .with_foo(nil) or .without_foo matchers do not seem to work as the string "nil" was passed tho puppet> context ''with parameter(s): foo => undef'' do > let(:params) {{ > :foo => nil, > }} > > [...] > endAny hints? Thanks in advance :-) [1] <http://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#undef> -- Andreas <http://blog.andreas-haerter.com>