3 # We don't need this for the basic tests we're doing
4 # require 'spec_helper'
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
10 describe Puppet::Parser::Functions.function(:validate_hash) do
12 # Pulled from Dan's create_resources function
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
23 describe 'when calling validate_hash from puppet' do
25 %w{ true false }.each do |the_string|
27 it "should not compile when #{the_string} is a string" do
28 Puppet[:code] = "validate_hash('#{the_string}')"
30 expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
33 it "should not compile when #{the_string} is a bare word" do
34 Puppet[:code] = "validate_hash(#{the_string})"
36 expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
41 it "should compile when multiple hash arguments are passed" do
42 Puppet[:code] = <<-'ENDofPUPPETcode'
44 $bar = { 'one' => 'two' }
45 validate_hash($foo, $bar)
48 @scope.compiler.compile
51 it "should not compile when an undef variable is passed" do
52 Puppet[:code] = <<-'ENDofPUPPETcode'
57 expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)