1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
4 tmpdir = default.tmpdir('stdlib')
6 describe 'loadyaml function' do
8 it 'loadyamls array of values' do
13 ddd: 4' > #{tmpdir}/testyaml.yaml")
15 $o = loadyaml('#{tmpdir}/testyaml.yaml')
16 notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>'))
17 notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>'))
18 notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>'))
19 notice(inline_template('loadyaml[ddd] is <%= @o["ddd"].inspect %>'))
22 apply_manifest(pp, :catch_failures => true) do |r|
23 expect(r.stdout).to match(/loadyaml\[aaa\] is 1/)
24 expect(r.stdout).to match(/loadyaml\[bbb\] is 2/)
25 expect(r.stdout).to match(/loadyaml\[ccc\] is 3/)
26 expect(r.stdout).to match(/loadyaml\[ddd\] is 4/)
30 it 'returns the default value if there is no file to load' do
32 $o = loadyaml('#{tmpdir}/no-file.yaml', {'default' => 'value'})
33 notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
36 apply_manifest(pp, :catch_failures => true) do |r|
37 expect(r.stdout).to match(/loadyaml\[default\] is "value"/)
41 it 'returns the default value if the file was parsed with an error' do
42 shell("echo '!' > #{tmpdir}/testyaml.yaml")
44 $o = loadyaml('#{tmpdir}/testyaml.yaml', {'default' => 'value'})
45 notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
48 apply_manifest(pp, :catch_failures => true) do |r|
49 expect(r.stdout).to match(/loadyaml\[default\] is "value"/)
54 it 'fails with no arguments'