]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
upgrade to concat 2.0.0
[dsa-puppet.git] / modules / stdlib / spec / unit / puppet / parser / functions / validate_bool_spec.rb
1 require 'puppet'
2
3 # We don't need this for the basic tests we're doing
4 # require 'spec_helper'
5
6 # Dan mentioned that Nick recommended the function method call
7 # to return the string value for the test description.
8 # this will not even try the test if the function cannot be
9 # loaded.
10 describe Puppet::Parser::Functions.function(:validate_bool) do
11
12   # Pulled from Dan's create_resources function
13   def get_scope
14     @topscope = Puppet::Parser::Scope.new
15     # This is necessary so we don't try to use the compiler to discover our parent.
16     @topscope.parent = nil
17     @scope = Puppet::Parser::Scope.new
18     @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => 'production'))
19     @scope.parent = @topscope
20     @compiler = @scope.compiler
21   end
22
23   describe 'when calling validate_bool from puppet' do
24
25     %w{ true false }.each do |the_string|
26
27       it "should not compile when #{the_string} is a string" do
28         Puppet[:code] = "validate_bool('#{the_string}')"
29         get_scope
30         expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
31       end
32
33       it "should compile when #{the_string} is a bare word" do
34         Puppet[:code] = "validate_bool(#{the_string})"
35         get_scope
36         @scope.compiler.compile
37       end
38
39     end
40
41     it "should not compile when an arbitrary string is passed" do
42       Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
43       get_scope
44       expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
45     end
46
47     it "should not compile when no arguments are passed" do
48       Puppet[:code] = 'validate_bool()'
49       get_scope
50       expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
51     end
52
53     it "should compile when multiple boolean arguments are passed" do
54       Puppet[:code] = <<-'ENDofPUPPETcode'
55         $foo = true
56         $bar = false
57         validate_bool($foo, $bar, true, false)
58       ENDofPUPPETcode
59       get_scope
60       @scope.compiler.compile
61     end
62
63     it "should compile when multiple boolean arguments are passed" do
64       Puppet[:code] = <<-'ENDofPUPPETcode'
65         $foo = true
66         $bar = false
67         validate_bool($foo, $bar, true, false, 'jeff')
68       ENDofPUPPETcode
69       get_scope
70       expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
71     end
72
73   end
74
75 end
76