Ask Your Question

content attribute in file resource not accepting numeric value in rspec-puppet

asked 2015-07-31 13:33:11 -0500

Chutki gravatar image


I have below resolv.conf file

nameserver 123.456.67.89

below is my manifests

file { 'resolv_conf' :
    ensure  => present,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => template('reconf/resolv.conf.erb'),

below is my rspec-puppet

it { should contain_file(resolv_conf).with_content( /nameserver 123.456.67.89/)}

I am getting error

  1) resolv_conf should contain File[resolv_conf] with  content =~ /nameserver 123.456.67.89/
     Failure/Error: )}
       expected that the catalogue would contain File[resolv_conf] with content set to /nameserver 123.456.67.89/ but it is set to "domain\nnameserver \n"
       @@ -1,2 +1,4 @@
       -(?-mix:nameserver 165.130.1. 9)
     # ./spec/classes/resolv_conf_spec.rb:11
Finished in 0.19464 seconds
1 example, 1 failure

but if write like below, it is working

it { should contain_file(resolv_conf).with_content( /domain}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-31 17:14:24 -0500

GregLarkin gravatar image

It appears that the test is working, but your Puppet code is not creating the resolv.conf file correctly. This is what your resolv.conf file contains when it is tested by rspec:


The nameserver value is blank, so check your code to see why that is happening.

edit flag offensive delete link more


you are correct. problem with manfests. Thanks.

Chutki gravatar imageChutki ( 2015-08-04 02:08:01 -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

1 follower


Asked: 2015-07-31 13:33:11 -0500

Seen: 365 times

Last updated: Jul 31 '15