Ask Your Question

name attribute doesn't in rspec-puppet

asked 2017-01-03 06:39:17 -0600

Chutki gravatar image

updated 2017-01-04 03:11:59 -0600


I have below manifests,

file {'module_name' :
    ensure => present,
    name   => '/etc/init.d/module_name',
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
    source => 'puppet:///modules/test/module_name',

Below is the rspec-puppet test case, when I run the test case getting error

    it { should contain_file('module_name').with(
             'ensure' => 'present',
             'name'   => '/etc/init.d/module_name',
             'owner'  => 'root',
             'group'  => 'root',
             'mode'   => '0755',
             'source' => 'puppet:///modules/test/module_name',

Error Message:

expected that the catalogue would contain File[module_name] with name set to "/etc/init.d/module_name" but it is set to nil

when I make 'name' => nilchange then my test case did pass.

============================================================== Second update, test.json

      "type": "File",
      "title": "module_name",
      "tags": ["file","module_name","class","module_name","module_name"],
      "file": "/root/modules_test/test/spec/fixtures/modules/test/manifests/test.pp",
      "line": 6,
      "exported": false,
      "parameters": {
        "path": "/etc/init.d/module_name",
        "ensure": "present",
        "owner": "root",
        "group": "root",
        "mode": "0755",
        "source": "puppet:///modules/oracle/module_name"
edit retag flag offensive close merge delete


I think that methods like 'contain_file' reference the title, not the name.

DarylW gravatar imageDarylW ( 2017-01-03 08:53:04 -0600 )edit

You also can put some debug in your rspec tests that print out the (pson) catalog for you to inspect what is actually present. ( note that you have to reference the `catalogue` object in your test

DarylW gravatar imageDarylW ( 2017-01-03 09:07:10 -0600 )edit

require 'spec_helper' describe 'module_name' do it { File.write( 'module_name.json', PSON.pretty_generate(catalogue) )}end # via

DarylW gravatar imageDarylW ( 2017-01-03 09:15:10 -0600 )edit

DarylW gravatar imageDarylW ( 2017-01-03 09:46:06 -0600 )edit

Hi, you can find the second update of json file in question box, I separated by "========". As you mentioned, I don't find attribute for "name" there. If 'content_file' refer the title as file name, then why we use "name" attribute in 'file' resource.

Chutki gravatar imageChutki ( 2017-01-04 03:18:07 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-02 05:01:14 -0600

David Schmitt gravatar image

The attribute is called path, not name: .

Do you have a it { compile.with_all_deps } test in your spec file? It should catch errors like this.

edit flag offensive delete link more

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: 2017-01-03 06:39:17 -0600

Seen: 225 times

Last updated: Oct 02 '17