1 #! /usr/bin/env ruby -S rspec
5 describe Puppet::Parser::Functions.function(:validate_string) do
6 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 describe 'when calling validate_string from puppet' do
10 %w{ foo bar baz }.each do |the_string|
12 it "should compile when #{the_string} is a string" do
13 Puppet[:code] = "validate_string('#{the_string}')"
14 scope.compiler.compile
17 it "should compile when #{the_string} is a bare word" do
18 Puppet[:code] = "validate_string(#{the_string})"
19 scope.compiler.compile
24 %w{ true false }.each do |the_string|
25 it "should compile when #{the_string} is a string" do
26 Puppet[:code] = "validate_string('#{the_string}')"
27 scope.compiler.compile
30 it "should not compile when #{the_string} is a bare word" do
31 Puppet[:code] = "validate_string(#{the_string})"
32 expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/)
36 it "should compile when multiple string arguments are passed" do
37 Puppet[:code] = <<-'ENDofPUPPETcode'
40 validate_string($foo, $bar)
42 scope.compiler.compile
45 it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
46 Puppet[:code] = <<-'ENDofPUPPETcode'
50 scope.compiler.compile
53 it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
54 Puppet[:code] = <<-'ENDofPUPPETcode'
55 validate_string($foobarbazishouldnotexist)
57 scope.compiler.compile