summaryrefslogtreecommitdiff
path: root/spec/unit/functions/with_spec.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/unit/functions/with_spec.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/unit/functions/with_spec.rb')
-rw-r--r--spec/unit/functions/with_spec.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/unit/functions/with_spec.rb b/spec/unit/functions/with_spec.rb
new file mode 100644
index 000000000..952b14412
--- /dev/null
+++ b/spec/unit/functions/with_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+require 'puppet_spec/compiler'
+require 'matchers/resource'
+
+describe 'the with function' do
+ include PuppetSpec::Compiler
+ include Matchers::Resource
+
+ before :each do
+ Puppet[:parser] = 'future'
+ end
+
+ it 'calls a lambda passing no arguments' do
+ expect(compile_to_catalog("with() || { notify { testing: } }")).to have_resource('Notify[testing]')
+ end
+
+ it 'calls a lambda passing a single argument' do
+ expect(compile_to_catalog('with(1) |$x| { notify { "testing$x": } }')).to have_resource('Notify[testing1]')
+ end
+
+ it 'calls a lambda passing more than one argument' do
+ expect(compile_to_catalog('with(1, 2) |*$x| { notify { "testing${x[0]}, ${x[1]}": } }')).to have_resource('Notify[testing1, 2]')
+ end
+
+ it 'passes a type reference to a lambda' do
+ expect(compile_to_catalog('notify { test: message => "data" } with(Notify[test]) |$x| { notify { "${x[message]}": } }')).to have_resource('Notify[data]')
+ end
+
+ it 'errors when not given enough arguments for the lambda' do
+ expect do
+ compile_to_catalog('with(1) |$x, $y| { }')
+ end.to raise_error(/Parameter \$y is required but no value was given/m)
+ end
+end