Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / parsejson_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'parsejson function' do
4   describe 'success' do
5     pp1 = <<-DOC
6       $a = '{"hunter": "washere", "tests": "passing"}'
7       $ao = parsejson($a)
8       $tests = $ao['tests']
9       notice(inline_template('tests are <%= @tests.inspect %>'))
10     DOC
11     it 'parses valid json' do
12       apply_manifest(pp1, :catch_failures => true) do |r|
13         expect(r.stdout).to match(%r{tests are "passing"})
14       end
15     end
16   end
17
18   describe 'failure' do
19     pp2 = <<-DOC
20       $a = '{"hunter": "washere", "tests": "passing",}'
21       $ao = parsejson($a, 'tests are using the default value')
22       notice(inline_template('a is <%= @ao.inspect %>'))
23     DOC
24     it 'raises error on incorrect json - default value is used' do
25       apply_manifest(pp2, :catch_failures => true) do |r|
26         expect(r.stdout).to match(%r{tests are using the default value})
27       end
28     end
29
30     pp3 = <<-DOC
31       $a = '{"hunter": "washere", "tests": "passing",}'
32       $ao = parsejson($a)
33       notice(inline_template('a is <%= @ao.inspect %>'))
34     DOC
35     it 'raises error on incorrect json' do
36       apply_manifest(pp3, :expect_failures => true) do |r|
37         expect(r.stderr).to match(%r{expected next name})
38       end
39     end
40
41     pp4 = <<-DOC
42       $o = parsejson()
43     DOC
44     it 'raises error on incorrect number of arguments' do
45       apply_manifest(pp4, :expect_failures => true) do |r|
46         expect(r.stderr).to match(%r{wrong number of arguments}i)
47       end
48     end
49   end
50 end