diff options
| author | Stig Sandbeck Mathisen <ssm@debian.org> | 2013-05-26 17:54:29 +0200 |
|---|---|---|
| committer | Stig Sandbeck Mathisen <ssm@debian.org> | 2013-05-26 17:54:29 +0200 |
| commit | 1a1e7395553ee2244cf3b9c75ac5ce84ebbc4775 (patch) | |
| tree | 7072a41b5b20a4a134607052954310c69867ed7a /spec/unit/parser/methods/shared.rb | |
| parent | 99de0b815d9c05804ddda33d5baa94b23ce1c39e (diff) | |
| parent | 025f00d05226e74a8ae68b2b16122b17a9746f2c (diff) | |
| download | puppet-upstream/3.2.1.tar.gz | |
Imported Upstream version 3.2.1upstream/3.2.1
Diffstat (limited to 'spec/unit/parser/methods/shared.rb')
| -rw-r--r-- | spec/unit/parser/methods/shared.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/unit/parser/methods/shared.rb b/spec/unit/parser/methods/shared.rb new file mode 100644 index 000000000..bf9c9f05f --- /dev/null +++ b/spec/unit/parser/methods/shared.rb @@ -0,0 +1,61 @@ + +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 defined with more than 1 argument' do + expect do + compile_to_catalog(<<-MANIFEST) + [1].#{func} { |$x, $yikes| } + MANIFEST + end.to raise_error(Puppet::Error, /Too few arguments/) + end + + it 'raises an error when defined with fewer than 1 argument' do + expect do + compile_to_catalog(<<-MANIFEST) + [1].#{func} { || } + MANIFEST + end.to raise_error(Puppet::Error, /Too many arguments/) + end + + it 'raises an error when used against an unsupported type' do + expect do + compile_to_catalog(<<-MANIFEST) + "not correct".#{func} { |$v| } + MANIFEST + end.to raise_error(Puppet::Error, /must be an Array or a Hash/) + 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, /Wrong number of arguments/) + 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, /Wrong number of arguments/) + end + + it 'raises an error when called without a block' do + expect do + compile_to_catalog(<<-MANIFEST) + [1].#{func}(1) + MANIFEST + end.to raise_error(Puppet::Error, /must be a parameterized block/) + end +end |
