1 require 'spec_helper_acceptance'
3 tmpdir = default.tmpdir('stdlib')
5 describe 'loadjson function' do
7 shell("echo '{\"aaa\":1,\"bbb\":2,\"ccc\":3,\"ddd\":4}' > #{tmpdir}/test1json.json")
9 $o = loadjson('#{tmpdir}/test1json.json')
10 notice(inline_template('loadjson[aaa] is <%= @o["aaa"].inspect %>'))
11 notice(inline_template('loadjson[bbb] is <%= @o["bbb"].inspect %>'))
12 notice(inline_template('loadjson[ccc] is <%= @o["ccc"].inspect %>'))
13 notice(inline_template('loadjson[ddd] is <%= @o["ddd"].inspect %>'))
15 regex_array = [%r{loadjson\[aaa\] is 1}, %r{loadjson\[bbb\] is 2}, %r{loadjson\[ccc\] is 3}, %r{loadjson\[ddd\] is 4}]
16 it 'loadjsons array of values' do
17 apply_manifest(pp1, :catch_failures => true) do |r|
18 regex_array.each do |i|
19 expect(r.stdout).to match(i)
25 $o = loadjson('#{tmpdir}/no-file.json', {'default' => 'value'})
26 notice(inline_template('loadjson[default] is <%= @o["default"].inspect %>'))
28 it 'returns the default value if there is no file to load' do
29 apply_manifest(pp2, :catch_failures => true) do |r|
30 expect(r.stdout).to match(%r{loadjson\[default\] is "value"})
34 shell("echo '!' > #{tmpdir}/test2json.json")
36 $o = loadjson('#{tmpdir}/test2json.json', {'default' => 'value'})
37 notice(inline_template('loadjson[default] is <%= @o["default"].inspect %>'))
39 it 'returns the default value if the file was parsed with an error' do
40 apply_manifest(pp3, :catch_failures => true) do |r|
41 expect(r.stdout).to match(%r{loadjson\[default\] is "value"})
46 it 'fails with no arguments'