1 #! /usr/bin/env ruby -S rspec
5 describe Puppet::Parser::Functions.function(:validate_bool) do
6 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 describe 'when calling validate_bool from puppet' do
9 %w{ true false }.each do |the_string|
11 it "should not compile when #{the_string} is a string" do
12 Puppet[:code] = "validate_bool('#{the_string}')"
13 expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
16 it "should compile when #{the_string} is a bare word" do
17 Puppet[:code] = "validate_bool(#{the_string})"
18 scope.compiler.compile
23 it "should not compile when an arbitrary string is passed" do
24 Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
25 expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
28 it "should not compile when no arguments are passed" do
29 Puppet[:code] = 'validate_bool()'
30 expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
33 it "should compile when multiple boolean arguments are passed" do
34 Puppet[:code] = <<-'ENDofPUPPETcode'
37 validate_bool($foo, $bar, true, false)
39 scope.compiler.compile
42 it "should compile when multiple boolean arguments are passed" do
43 Puppet[:code] = <<-'ENDofPUPPETcode'
46 validate_bool($foo, $bar, true, false, 'jeff')
48 expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)