]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/validate_bool_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_bool_spec.rb
1 #! /usr/bin/env ruby -S rspec
2
3 require 'spec_helper'
4
5 describe Puppet::Parser::Functions.function(:validate_bool) do
6   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7   describe 'when calling validate_bool from puppet' do
8
9     %w{ true false }.each do |the_string|
10
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/)
14       end
15
16       it "should compile when #{the_string} is a bare word" do
17         Puppet[:code] = "validate_bool(#{the_string})"
18         scope.compiler.compile
19       end
20
21     end
22
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/)
26     end
27
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/)
31     end
32
33     it "should compile when multiple boolean arguments are passed" do
34       Puppet[:code] = <<-'ENDofPUPPETcode'
35         $foo = true
36         $bar = false
37         validate_bool($foo, $bar, true, false)
38       ENDofPUPPETcode
39       scope.compiler.compile
40     end
41
42     it "should compile when multiple boolean arguments are passed" do
43       Puppet[:code] = <<-'ENDofPUPPETcode'
44         $foo = true
45         $bar = false
46         validate_bool($foo, $bar, true, false, 'jeff')
47       ENDofPUPPETcode
48       expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
49     end
50   end
51 end