summaryrefslogtreecommitdiff
path: root/spec/shared_behaviours/iterative_functions.rb
diff options
context:
space:
mode:
authorStig Sandbeck Mathisen <ssm@debian.org>2014-09-07 10:14:36 +0200
committerStig Sandbeck Mathisen <ssm@debian.org>2014-09-07 10:14:36 +0200
commitd4b83be375ac1dead058e091191ee7c7b7c24c8a (patch)
treedc825687392ae3068de5b764be60c53122d9e02a /spec/shared_behaviours/iterative_functions.rb
parent229cbb976fe0f70f5f30548b83517b415840f9bb (diff)
parent1681684857c6e39d60d87b0b3520d8783977ceff (diff)
downloadpuppet-upstream/3.7.0.tar.gz
Imported Upstream version 3.7.0upstream/3.7.0
Diffstat (limited to 'spec/shared_behaviours/iterative_functions.rb')
-rw-r--r--spec/shared_behaviours/iterative_functions.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/shared_behaviours/iterative_functions.rb b/spec/shared_behaviours/iterative_functions.rb
new file mode 100644
index 000000000..1910a3c80
--- /dev/null
+++ b/spec/shared_behaviours/iterative_functions.rb
@@ -0,0 +1,69 @@
+
+shared_examples_for 'all iterative functions hash handling' do |func|
+ it 'passes a hash entry as an array of the key and value' do
+ catalog = compile_to_catalog(<<-MANIFEST)
+ {a=>1}.#{func} |$v| { notify { "${v[0]} ${v[1]}": } }
+ MANIFEST
+
+ catalog.resource(:notify, "a 1").should_not be_nil
+ end
+end
+
+shared_examples_for 'all iterative functions argument checks' do |func|
+
+ it 'raises an error when used against an unsupported type' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ 3.14.#{func} |$k, $v| { }
+ MANIFEST
+ end.to raise_error(Puppet::Error, /must be something enumerable/)
+ end
+
+ it 'raises an error when called with any parameters besides a block' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ [1].#{func}(1) |$v| { }
+ MANIFEST
+ end.to raise_error(Puppet::Error, /mis-matched arguments.*expected.*arg count \{2\}.*actual.*arg count \{3\}/m)
+ end
+
+ it 'raises an error when called without a block' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ [1].#{func}()
+ MANIFEST
+ end.to raise_error(Puppet::Error, /mis-matched arguments.*expected.*arg count \{2\}.*actual.*arg count \{1\}/m)
+ end
+
+ it 'raises an error when called with something that is not a block' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ [1].#{func}(1)
+ MANIFEST
+ end.to raise_error(Puppet::Error, /mis-matched arguments.*expected.*Callable.*actual(?!Callable\)).*/m)
+ end
+
+ it 'raises an error when called with a block with too many required parameters' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ [1].#{func}() |$v1, $v2, $v3| { }
+ MANIFEST
+ end.to raise_error(Puppet::Error, /mis-matched arguments.*expected.*arg count \{2\}.*actual.*Callable\[Any, Any, Any\]/m)
+ end
+
+ it 'raises an error when called with a block with too few parameters' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ [1].#{func}() | | { }
+ MANIFEST
+ end.to raise_error(Puppet::Error, /mis-matched arguments.*expected.*arg count \{2\}.*actual.*Callable\[0, 0\]/m)
+ end
+
+ it 'does not raise an error when called with a block with too many but optional arguments' do
+ expect do
+ compile_to_catalog(<<-MANIFEST)
+ [1].#{func}() |$v1, $v2, $v3=extra| { }
+ MANIFEST
+ end.to_not raise_error
+ end
+end