rspec ArgumentError:参数个数错误(0表示1)

时间:2014-06-05 10:02:55

标签: ruby rspec puppet

我正在尝试使用rspec和puppet来检查.erb文件中配置文件的生成。但是,我收到了错误

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

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

如何修复错误"错误的参数数量"?

1 个答案:

答案 0 :(得分:1)

我认为您正在混合rspecrspec-puppet样式代码。

如果您正在测试logstash课程,那么您的rspec-puppet代码应该是

# 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

请注意,我从未在此上下文中使用正则表达式,但这是您要遵循的一般结构。