X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fsprintf_hash_spec.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fsprintf_hash_spec.rb;h=4bead465ce1a1cac1f3d363990bcd284d885ec3e;hb=9dd86576df2182653f8e96f51f11c917341eb4ce;hp=0000000000000000000000000000000000000000;hpb=88887aa2a8ca345d6f79fccb336a9bb9ae8443a2;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/sprintf_hash_spec.rb b/3rdparty/modules/stdlib/spec/functions/sprintf_hash_spec.rb new file mode 100644 index 000000000..4bead465c --- /dev/null +++ b/3rdparty/modules/stdlib/spec/functions/sprintf_hash_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'sprintf_hash' do + it 'exists' do + is_expected.not_to eq(nil) + end + + context 'with param count' do + it 'fails with no arguments' do + is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects 2 arguments}i) + end + it 'fails with 1 argument' do + is_expected.to run.with_params('').and_raise_error(ArgumentError, %r{expects 2 arguments}i) + end + it 'fails with too many arguments' do + is_expected.to run.with_params('', '', '').and_raise_error(ArgumentError, %r{expects 2 arguments}i) + end + end + + context 'with param type' do + it 'fails with wrong format type' do + is_expected.to run.with_params(false, {}).and_raise_error(ArgumentError, %r{parameter 'format' expects a String value}i) + end + it 'fails with wrong arguments type' do + is_expected.to run.with_params('', false).and_raise_error(ArgumentError, %r{parameter 'arguments' expects a Hash value}i) + end + end + + it 'prints formats with name placeholders' do + is_expected.to run.with_params('string %s and integer %b', 'foo' => '_foo_', 'bar' => 5) # rubocop:disable Style/FormatStringToken : Template tokens needed for purposes of test + .and_return('string _foo_ and integer 101') + end +end