]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/validate_hash_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_hash_spec.rb
1 #! /usr/bin/env ruby -S rspec
2
3 require 'spec_helper'
4
5 describe Puppet::Parser::Functions.function(:validate_hash) do
6   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
8   describe 'when calling validate_hash from puppet' do
9
10     %w{ true false }.each do |the_string|
11
12       it "should not compile when #{the_string} is a string" do
13         Puppet[:code] = "validate_hash('#{the_string}')"
14         expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
15       end
16
17       it "should not compile when #{the_string} is a bare word" do
18         Puppet[:code] = "validate_hash(#{the_string})"
19         expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
20       end
21
22     end
23
24     it "should compile when multiple hash arguments are passed" do
25       Puppet[:code] = <<-'ENDofPUPPETcode'
26         $foo = {}
27         $bar = { 'one' => 'two' }
28         validate_hash($foo, $bar)
29       ENDofPUPPETcode
30       scope.compiler.compile
31     end
32
33     it "should not compile when an undef variable is passed" do
34       Puppet[:code] = <<-'ENDofPUPPETcode'
35         $foo = undef
36         validate_hash($foo)
37       ENDofPUPPETcode
38       expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
39     end
40
41   end
42
43 end