Ask Your Question
0

rspec-puppet does not support file_line resource

asked 2015-07-23 06:44:02 -0500

Chutki gravatar image

Hi,

I have below manifests with file_line resource

class login {

  if $::operatingsystemmajrelease < 7 {

    file {'/etc/loginfile':
      ensure => present,
    }

    file_line { 'testfile':
      path   => '/etc/loginfile',
      line   => 'abc 022',
      match  => '^abc.*$',
    }
  }
}

Below is rspec file

require 'spec_helper'

describe 'login' do

  it { should contain_class('login')}

  let(:facts) {{:operatingsystemmajrelease => 6}}

  if (6 < 7)
    it { should contain_file('/etc/loginfile').with_ensure('present')}

    it { should contain_file_line('testfile').with(
      :path   => '/etc/loginfile',
      :line   => 'abc 022',
      :match  => '^abc.*$'
    )}
  end
end

When I run rake-spec command getting below error

 login
     Failure/Error: it { should contain_class('login')}
     Puppet::Error:
       Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type file_line at /etc/puppetlabs/modulename/login/spec/fixtures/modules/login_defs/manifests/init.pp:17 on node 
     # ./spec/classes/login_spec.rb:5
rspec will not support file_line resporce?

Becase if I remove "file_line" resource and run rsepc file its working

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-07-23 11:15:10 -0500

GregLarkin gravatar image

updated 2015-07-31 01:03:57 -0500

It sounds like you need to set up a fixtures file to pull in your module dependencies: https://github.com/puppetlabs/puppetlabsspechelper#using-fixtures

UPDATE: Now that you have set up your .fixtures.yml file, make sure that you have git installed on your machine. If you don't, the "git clone" operation will fail.

edit flag offensive delete link more

Comments

Already file directory was linked to fixtures file "lrwxrwxrwx 1 root root 17 Jul 17 08:38 files -> ../../../../files" under spec/fixtures/modules/modulename

Chutki gravatar imageChutki ( 2015-07-24 07:13:14 -0500 )edit

Did you follow this instruction? "puppetlabs_spec_helper has the ability to populate the spec/fixtures/modules directory with dependent modules when rake spec or rake spec_prep is run. To do so, all required modules should be listed in a file named .fixtures.yml in the root of the project."

GregLarkin gravatar imageGregLarkin ( 2015-07-24 13:05:49 -0500 )edit

Please post your .fixtures.yml file somewhere for review.

GregLarkin gravatar imageGregLarkin ( 2015-07-24 13:06:01 -0500 )edit

I installed gem "puppetlabs_spec_helper" but when I run "rake spec" getting an error "/usr/bin/ruby -I/usr/lib/ruby/gems/1.8/gems/rspec-support-3.3.0/lib:/usr/lib/ruby/gems/1.8/gems/rspec-core-3.3.2/lib /usr/lib/ruby/gems/1.8/gems/rspec-core-3.3.2/exe/rspec --pattern spec/\*/\*_spec.rb"

Chutki gravatar imageChutki ( 2015-07-27 11:48:06 -0500 )edit

Please post your .fixtures.yml file somewhere for review.

GregLarkin gravatar imageGregLarkin ( 2015-07-27 15:55:56 -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

Stats

Asked: 2015-07-23 06:44:02 -0500

Seen: 540 times

Last updated: Jul 31 '15