Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / parseyaml_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
3
4 describe 'parseyaml function' do
5   describe 'success' do
6     it 'parses valid yaml' do
7       pp = <<-EOS
8       $a = "---\nhunter: washere\ntests: passing\n"
9       $o = parseyaml($a)
10       $tests = $o['tests']
11       notice(inline_template('tests are <%= @tests.inspect %>'))
12       EOS
13
14       apply_manifest(pp, :catch_failures => true) do |r|
15         expect(r.stdout).to match(/tests are "passing"/)
16       end
17     end
18   end
19
20   describe 'failure' do
21     it 'returns the default value on incorrect yaml' do
22       pp = <<-EOS
23       $a = "---\nhunter: washere\ntests: passing\n:"
24       $o = parseyaml($a, {'tests' => 'using the default value'})
25       $tests = $o['tests']
26       notice(inline_template('tests are <%= @tests.inspect %>'))
27       EOS
28
29       apply_manifest(pp, :catch_failures => true) do |r|
30         expect(r.stdout).to match(/tests are "using the default value"/)
31       end
32     end
33
34     it 'raises error on incorrect yaml' do
35       pp = <<-EOS
36       $a = "---\nhunter: washere\ntests: passing\n:"
37       $o = parseyaml($a)
38       $tests = $o['tests']
39       notice(inline_template('tests are <%= @tests.inspect %>'))
40       EOS
41
42       apply_manifest(pp, :expect_failures => true) do |r|
43         expect(r.stderr).to match(/(syntax error|did not find expected key)/)
44       end
45     end
46
47
48     it 'raises error on incorrect number of arguments' do
49       pp = <<-EOS
50       $o = parseyaml()
51       EOS
52
53       apply_manifest(pp, :expect_failures => true) do |r|
54         expect(r.stderr).to match(/wrong number of arguments/i)
55       end
56     end
57   end
58 end