1 require 'spec_helper_acceptance'
3 tmpdir = default.tmpdir('stdlib')
5 describe 'loadyaml function' do
11 ddd: 4' > #{tmpdir}/test1yaml.yaml")
13 $o = loadyaml('#{tmpdir}/test1yaml.yaml')
14 notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>'))
15 notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>'))
16 notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>'))
17 notice(inline_template('loadyaml[ddd] is <%= @o["ddd"].inspect %>'))
19 regex_array = [%r{loadyaml\[aaa\] is 1}, %r{loadyaml\[bbb\] is 2}, %r{loadyaml\[ccc\] is 3}, %r{loadyaml\[ddd\] is 4}]
20 it 'loadyamls array of values' do
21 apply_manifest(pp1, :catch_failures => true) do |r|
22 regex_array.each do |i|
23 expect(r.stdout).to match(i)
29 $o = loadyaml('#{tmpdir}/no-file.yaml', {'default' => 'value'})
30 notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
32 it 'returns the default value if there is no file to load' do
33 apply_manifest(pp2, :catch_failures => true) do |r|
34 expect(r.stdout).to match(%r{loadyaml\[default\] is "value"})
38 shell("echo '!' > #{tmpdir}/test2yaml.yaml")
40 $o = loadyaml('#{tmpdir}/test2yaml.yaml', {'default' => 'value'})
41 notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
43 it 'returns the default value if the file was parsed with an error' do
44 apply_manifest(pp3, :catch_failures => true) do |r|
45 expect(r.stdout).to match(%r{loadyaml\[default\] is "value"})
50 it 'fails with no arguments'