1.8.7
次のgemファイルで実行されるRubyバージョンを使用してパペットモジュールを開発し、bundle install
rspecテストが正常に機能しました(パペットも実行されました):
source 'https://rubygems.org'
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', '3.7.5'
end
gem 'metadata-json-lint'
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet-facts'
# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
end
ただし、Ruby を使用する CI サーバーでbundle install
同じことを行ったときに、次の rspec エラーが発生しました。Gemfile
1.9.3
一般的なエラーは次のとおりです。
Puppet::Error:
Failed to parse template silex/var/config/settings.json.erb:
Filepath: /var/tmp/silex/spec/fixtures/modules/silex/templates/var/config/settings.json.erb
Line: 4
Detail: undefined method `each_with_index' for "default":String
メソッドを使用するテンプレートeach_with_index
:
{
"elasticsearch.settings": {
"connections": [
<% @elastic_hosts.each_with_index do |host,i| -%>
{"host":"<%= host['ip'] %>", "port": <%= host['port'] %> }<%= ',' if i < (@elastic_hosts.size - 1) -%>
<% end -%>
],
"index": "<%= @elastic_index %>"
}
},
"cache.lifetime": <%= @elastic_cache_lifetime %>,
"environment": "dev",
"trusted": [
<% @trusted_hosts.each_with_index do |host,i| -%>
{"host":"<%= host['host'] %>"}<%= ',' if i < (@trusted_hosts.size - 1) -%>
<% end -%>
],
"homepage.settings": {
"hero.count": 20,
"list.count": 20
}
}
別のバージョンのルビーでこれが失敗する理由を理解できていませんか? ルビーも試してみまし2.1.1
たが、同じ結果でした。1.8.7
結果は、Ruby を使用した CI サーバー(モジュールの開発に使用したのと同じバージョン)でのみ成功します。
更新 1
elastic_hosts
はハッシュ マップであり、文字列が失敗したためです。これを (別のハッシュ マップ) と共に修正したtrusted_hosts
結果、ほとんどのテストはパスしましたが、エラーは解決しません。
注: エラーは、上で強調表示されている一般的なエラーから変更されていません。
上記のテンプレート ファイルも完全な内容で更新しました。
私の構成仕様ファイルを見ると、default
どこにも文字列として指定していませんが、それはエラーであることがわかります..
修理
疑わしいように、私の初期仕様クラスにはデフォルトが設定されており、hiera ルックアップを追加して問題elastic_hosts
をtrusted_hosts
修正しました。
更新 2
1.8.7
この動作は、バージョンとバージョン >の間で再現可能1.9.3
です。ハッシュの扱い方に何か関係があるようです。