Add missing new files from commit 131e09855e06
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / sprintf_hash_spec.rb
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 (file)
index 0000000..4bead46
--- /dev/null
@@ -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 %<foo>s and integer %<bar>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