Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / try_get_value_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
3
4 describe 'try_get_value function' do
5   describe 'success' do
6     it 'gets a value' do
7       pp = <<-EOS
8       $data = {
9         'a' => { 'b' => 'passing'}
10       }
11
12       $tests = try_get_value($data, 'a/b')
13       notice(inline_template('tests are <%= @tests.inspect %>'))
14       EOS
15
16       apply_manifest(pp, :catch_failures => true) do |r|
17         expect(r.stdout).to match(/tests are "passing"/)
18       end
19     end
20   end
21   describe 'failure' do
22     it 'uses a default value' do
23       pp = <<-EOS
24       $data = {
25         'a' => { 'b' => 'passing'}
26       }
27
28       $tests = try_get_value($data, 'c/d', 'using the default value')
29       notice(inline_template('tests are <%= @tests.inspect %>'))
30       EOS
31
32       apply_manifest(pp, :catch_failures => true) do |r|
33         expect(r.stdout).to match(/using the default value/)
34       end
35     end
36
37     it 'raises error on incorrect number of arguments' do
38       pp = <<-EOS
39       $o = try_get_value()
40       EOS
41
42       apply_manifest(pp, :expect_failures => true) do |r|
43         expect(r.stderr).to match(/wrong number of arguments/i)
44       end
45     end
46   end
47 end