Dennis
Dennis

Reputation: 2964

Puppet-rspec keeps failing on error trying to convert from string to integer

I keep on getting this error in 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

Template line 6:

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

Spec test:

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       

Upvotes: 0

Views: 552

Answers (1)

Felix Frank
Felix Frank

Reputation: 8223

Your iterator does not do what you think it does.

You could either

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

or perhaps (and I assume this is your problem) you actually need to pass an array of hashes.

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

Upvotes: 1

Related Questions