]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/validate_string_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_string_spec.rb
1 #! /usr/bin/env ruby -S rspec
2
3 require 'spec_helper'
4
5 describe Puppet::Parser::Functions.function(:validate_string) do
6   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
8   describe 'when calling validate_string from puppet' do
9
10     %w{ foo bar baz }.each do |the_string|
11
12       it "should compile when #{the_string} is a string" do
13         Puppet[:code] = "validate_string('#{the_string}')"
14         scope.compiler.compile
15       end
16
17       it "should compile when #{the_string} is a bare word" do
18         Puppet[:code] = "validate_string(#{the_string})"
19         scope.compiler.compile
20       end
21
22     end
23
24     %w{ true false }.each do |the_string|
25       it "should compile when #{the_string} is a string" do
26         Puppet[:code] = "validate_string('#{the_string}')"
27         scope.compiler.compile
28       end
29
30       it "should not compile when #{the_string} is a bare word" do
31         Puppet[:code] = "validate_string(#{the_string})"
32         expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/)
33       end
34     end
35
36     it "should compile when multiple string arguments are passed" do
37       Puppet[:code] = <<-'ENDofPUPPETcode'
38         $foo = ''
39         $bar = 'two'
40         validate_string($foo, $bar)
41       ENDofPUPPETcode
42       scope.compiler.compile
43     end
44
45     it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
46       Puppet[:code] = <<-'ENDofPUPPETcode'
47         $foo = undef
48         validate_string($foo)
49       ENDofPUPPETcode
50       scope.compiler.compile
51     end
52
53     it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
54       Puppet[:code] = <<-'ENDofPUPPETcode'
55         validate_string($foobarbazishouldnotexist)
56       ENDofPUPPETcode
57       scope.compiler.compile
58     end
59   end
60 end