Ask Your Question

getting expected catalogue error when pass parameter in rspec

asked 2016-03-01 04:35:16 -0500

Chutki gravatar image

updated 2016-03-01 06:25:10 -0500


I have below manifests

define module::defclass ($dir,$fs_name=$title)

 exec { " '${dir}' exists" :
    path    => [ '/bin', '/usr/bin' ],
    command => "mkdir -p ${dir}",
    unless  => "test -d ${dir}",

Below is the rspec-puppet for this

let(:params) do { :dir => '/opt/ab/bc/' } end

it { should contain_exec(' /opt/ab/bc/ exists').with(
  'path'    => ['/bin','/usr/bin'],
  'command' => 'mkdir -p /opt/ab/bc',
  'unless'  => 'test -d /opt/ab/bc'

when I run this getting

Failure/Error: )}
       expected that the catalogue would contain Exec[/opt/ab/bc exists]
     # ./spec/defines/fs_spec.rb:5:in `block (2 levels) in <top (required)>'

I am breaking my head to find out the bug in my test file, but I have no clue the cause of this.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-01 05:01:06 -0500

updated 2016-03-01 05:05:51 -0500

In your manifest you create a resource with title:

" '${dir}' exists"

Notice there is a space, followed by a hard quote, followed by $dir, followed by another hard quote, followed by a space and the string "exists".

In your rspec test you expect the resource to have a title that is simply $dir, followed by a space, followed by the string "exists".

It would probably help you if you learnt how to manually compile catalogs. I wrote a blog post here that shows you how to do this.

It would help you, because you can then inspect the catalogs for the nodes you're having trouble with in a text editor. It might help you figure out why your rspec tests aren't succeeding.

edit flag offensive delete link more


Yes, I tried to include the space followed by hard code but still getting the same error.

Chutki gravatar imageChutki ( 2016-03-01 05:37:28 -0500 )edit

Well I can't see what your code is now so I can't comment on why you're still getting an error.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-01 05:54:28 -0500 )edit

I edited rspec-puppet test file code

Chutki gravatar imageChutki ( 2016-03-01 06:25:37 -0500 )edit

As I said already, your manifest has hard quotes in the string: " '/opt/ab/bc/' exists" whereas you are expecting " /opt/ab/bc/ exists". So they're not the same. I guess you need to read up on how to quote quotation marks.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-01 09:26:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-03-01 04:35:16 -0500

Seen: 80 times

Last updated: Mar 01 '16