Sorry for bringing up an old thread, but I hit the same issue and found
a workaround.
rspec-puppet calls #inspect on the parameter values to see how they
should be represented in Puppet's DSL, so passing a string in causes it
to get quoted (as String#inspect returns a quoted string).
Instead, I created a small class that returns an unquoted value.
in spec_helper.rb:
class Undef
def inspect
'undef'
end
end
and then to use it:
let(:params) do
{ :example => Undef.new }
end
--
Dominic Cleal
Red Hat Engineering
On 27/04/14 15:38, Remi Ferrand wrote:
> Hi everyone,
>
> thanks all for your answers but i'm starting to think that there is way
> to pass puppet "undef" value from a rspec test...
> If anybody has the solution to fix this test suite
> (https://github.com/riton/puppetrspec) please tell me; otherwise I'll
> have to rewrite my manifests and replace the puppet "undef" value with a
> simple "undef" string where it is possible...
>
> It doesn't have the same meaning but it can help me moving on with my
> test suite.
>
> Thaks.
>
> Rémi
>
>
> On Tue, Apr 22, 2014 at 12:57 PM, Nan Liu <[email protected]
> <mailto:[email protected]>> wrote:
>
> On Tue, Apr 22, 2014 at 4:34 AM, Remi Ferrand
> <[email protected]
> <mailto:[email protected]>> wrote:
>
> Hi Nan,
>
> thanks for your answer.
> With this modification:
>
> diff --git a/spec/classes/puppetrspec_spec.rb
> b/spec/classes/puppetrspec_spec.rb
> index 9d06d79..80fae58 100644
> --- a/spec/classes/puppetrspec_spec.rb
> +++ b/spec/classes/puppetrspec_spec.rb
> @@ -22,7 +22,7 @@ describe 'puppetrspec', :type => :class do
> context 'with ensure undef' do
>
> let :params do {
> - :ensure => '# WHAT SHOULD WE USE HERE TO PASS
> PUPPET undef VALUE ?#'
> + :ensure => :undef
> } end
>
> it 'should have File with ensure absent' do
>
>
> it fails with this error:
>
> % rake spec
> /usr/bin/ruby -S rspec spec/classes/puppetrspec_spec.rb --color
> .F
>
> Failures:
>
> 1) puppetrspec with ensure undef should have File with ensure
> absent
> Failure/Error: should
> contain_file(filename).with_ensure('absent')
> Puppet::Error:
> Could not parse for environment production: Syntax error
> at ':'; expected '}' at line 4 on node ...
> # ./spec/classes/puppetrspec_spec.rb:30
>
> Finished in 1.51 seconds
> 2 examples, 1 failure
>
> Failed examples:
>
> rspec ./spec/classes/puppetrspec_spec.rb:29 # puppetrspec with
> ensure undef should have File with ensure absent
>
>
> Same error with this modification:
>
> diff --git a/spec/classes/puppetrspec_spec.rb
> b/spec/classes/puppetrspec_spec.rb
> index 9d06d79..63faa11 100644
> --- a/spec/classes/puppetrspec_spec.rb
> +++ b/spec/classes/puppetrspec_spec.rb
> @@ -21,9 +21,9 @@ describe 'puppetrspec', :type => :class do
>
> context 'with ensure undef' do
>
> - let :params do {
> - :ensure => '# WHAT SHOULD WE USE HERE TO PASS
> PUPPET undef VALUE ?#'
> - } end
> + let(:params) {{
> + :ensure => :undef
> + }}
>
>
> If you have any other idea, let me know :-)
>
>
> So internally it appears to be :undef, and I thought that would work
> for rspec, but clearly not.
>
> https://github.com/puppetlabs/puppet/blob/master/spec/unit/parser/ast/leaf_spec.rb#L101
>
> Trying to set it to Puppet::Parser::AST::Undef resulted in the wrong
> behavior with "if $var {...}". I may have mixed this up with a
> puppet function where I needed to return undef. I guess I shouldn't
> count on my memory at this hour of the day.
>
> Nan
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Puppet Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-users/6nL2eROH8is/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
>
> https://groups.google.com/d/msgid/puppet-users/CACqVBqBGogT4Fig6fsH5drRjyRPyJcTmnkxBYh2gSOYyfutaUg%40mail.gmail.com
>
> <https://groups.google.com/d/msgid/puppet-users/CACqVBqBGogT4Fig6fsH5drRjyRPyJcTmnkxBYh2gSOYyfutaUg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAMTZwM%2B%2BWXCWeijX%3DRJs%3DVoeRs7apQY4CypePLGp%2B1mJQZ9aoA%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-users/CAMTZwM%2B%2BWXCWeijX%3DRJs%3DVoeRs7apQY4CypePLGp%2B1mJQZ9aoA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" 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-users/53BA548E.2070908%40redhat.com.
For more options, visit https://groups.google.com/d/optout.