Puppet-rspec在尝试从字符串转换为整数时出错

时间:2015-08-11 16:12:35

标签: rspec puppet

我继续在Puppet中收到此错误:

 1) hazelcast with defaults for all parameters should contain Class[hazelcast]
     Failure/Error: it { is_expected.to contain_class('hazelcast') }
     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, Failed to parse template hazelcast/hazelcast.startup.sh.erb:
         Filepath: modules/hazelcast/spec/fixtures/modules/hazelcast/templates/hazelcast.startup.sh.erb
         Line: 6
         Detail: no implicit conversion of String into Integer

模板第6行:

EXTRA_CLASSPATH=<% scope['hazelcast::extra_libraries'].each do |extra_library| %>:$LIBS_DIR/<%= extra_library['file'] %><% end %>

规格测试:

require 'spec_helper'
describe 'hazelcast' do

  # Some general facts to assume we're running on Linux
  let :facts do {
    id:                     'root',
    kernel:                 'Linux',
    osfamily:               'RedHat',
    operatingsystem:        'RedHat',
    operatingsystemrelease: '7' }
  end

  context 'with defaults for all parameters' do
    it { expect { is_expected.to contain_class('hazelcast') }.to raise_error(Puppet::Error) }
  end

  required_params = {
    extra_libraries: {'url' => 'bla', 'file' => 'bla'},
    servers: ['1','2'],
  }

  context 'with defaults for all parameters' do
    let(:params) { required_params }
    it { is_expected.to contain_class('hazelcast') }
  end

end       

1 个答案:

答案 0 :(得分:1)

您的迭代器不会按照您的想法执行。

你可以

scope['hazelcast::extra_libraries'].each_key do |extra_library|

或者(我认为这是你的问题)你实际上需要传递一个哈希数组。

extra_libraries: [ {'url' => 'bla', 'file' => 'bla'} ],