Add missing new files from commit 131e09855e06
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / sprintf_hash_spec.rb
1 require 'spec_helper'
2
3 describe 'sprintf_hash' do
4   it 'exists' do
5     is_expected.not_to eq(nil)
6   end
7
8   context 'with param count' do
9     it 'fails with no arguments' do
10       is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects 2 arguments}i)
11     end
12     it 'fails with 1 argument' do
13       is_expected.to run.with_params('').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
14     end
15     it 'fails with too many arguments' do
16       is_expected.to run.with_params('', '', '').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
17     end
18   end
19
20   context 'with param type' do
21     it 'fails with wrong format type' do
22       is_expected.to run.with_params(false, {}).and_raise_error(ArgumentError, %r{parameter 'format' expects a String value}i)
23     end
24     it 'fails with wrong arguments type' do
25       is_expected.to run.with_params('', false).and_raise_error(ArgumentError, %r{parameter 'arguments' expects a Hash value}i)
26     end
27   end
28
29   it 'prints formats with name placeholders' do
30     is_expected.to run.with_params('string %<foo>s and integer %<bar>b', 'foo' => '_foo_', 'bar' => 5) # rubocop:disable Style/FormatStringToken : Template tokens needed for purposes of test
31                       .and_return('string _foo_ and integer 101')
32   end
33 end