Question

I am trying to use rspec with puppet to check the generation of a configuration file from an .erb file. However, I get the error

1) customizations should generate valid logstash.conf
     Failure/Error: content = catalogue.resource('file', 'logstash.conf').send(:parameters)[:content]
     ArgumentError:
       wrong number of arguments (0 for 1)
     # ./spec/classes/logstash_spec.rb:29:in `catalogue'
     # ./spec/classes/logstash_spec.rb:29

And the logstash_spec.rb:

describe "customizations" do
    let(:params) { {:template => "profiles/logstash/output_broker.erb", :options => {'opt_a' => 'value_a' } } }
    it 'should generate valid logstash.conf' do
      content = catalogue.resource('file', 'logstash.conf').send(:parameters)[:content]
      content.should match('logstash')
    end
end

How do I fix the error "wrong number of arguments"?

Was it helpful?

Solution

I think you are mixing rspec and rspec-puppet style code.

If you are testing your logstash class, your rspec-puppet code should look like

# spec/classes/logstash_spec.rb

require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}"

describe 'logstash' do
  let(:params) { {:template => "profiles/logstash/output_broker.erb", :options => {'opt_a' => 'value_a' } } }
  it { should contain_file('logstash.conf').with_content(/logstash/) }
end

Note that I never tried with regex in this context, but that is the general structure you want to follow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top