Ask Your Question

resource defaults unable to add in rspec-puppet

asked 2015-08-06 06:27:28 -0500

Chutki gravatar image


I am using default resource for one of the module

File {
      ensure => present,
      owner  => 'root',
      group  => 'root',
      mode   => '0644',

file { '/etc/test' :
      source => 'puppet:///modules/testmodule/file',

below is the rspec test case

 it {should contain_file ().with( 
    :ensure => 'present',
    :owner  => 'root',
    :group  => 'root',
    :mode   => '0644'

  it { should contain_file('/etc/test').with_source('puppet:///modules/testmodule/file')}

I am getting below error

module should contain File[] with group => "root", ensure => "present", owner => "root" and mode => "0644"
     Failure/Error: )}
       expected that the catalogue would contain File[]
     # ./spec/classes/module_spec.rb:12

I tried below merge option, but no luck :(

 let(:defaults) {{
    :ensure => 'present',
    :owner  => 'root',
    :group  => 'root',
    :mode   => '0644'

  it { should contain_file('/etc/test').with_source('puppet:///modules/testmodule/file').merge(defaults)}

below error I am getting for merge option


  1) module
     Failure/Error: it { should contain_file('/etc/test').with_source('puppet:///modules/testmodule/file').merge(defaults)}
       undefined method `merge' for #<RSpec::Puppet::ManifestMatchers::CreateGeneric:0x7fecc70a4fb8>
     # ./spec/classes/module_spec.rb:14
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-08-06 20:38:11 -0500

GregLarkin gravatar image

updated 2015-08-07 13:56:56 -0500

Can you supply a pointer to the documentation for the merge() function in rspec-puppet? I was unable to find any information about it. If it doesn't exist, then you'll need to remove it from your code.


Check the page that you referenced again, and you'll see that the .merge() method is called on a hash of attributes. Merge is not a method from rspec-puppet, it's a Ruby method for hashes. You have to rewrite your code to call merge in the correct context in your test.

edit flag offensive delete link more

Comments - url I referred

Chutki gravatar imageChutki ( 2015-08-07 08:45:23 -0500 )edit

do we have any other option to call resource defaults in rspec-puppet

Chutki gravatar imageChutki ( 2015-08-17 06:22: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-08-06 06:27:28 -0500

Seen: 238 times

Last updated: Aug 07 '15