2012-07-20 01:14:37 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-08-04 00:51:27 +02:00
|
|
|
|
2012-07-20 01:14:37 +02:00
|
|
|
require 'spec_helper'
|
2011-08-04 00:51:27 +02:00
|
|
|
|
|
|
|
describe Puppet::Parser::Functions.function(:validate_array) do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-08-04 00:51:27 +02:00
|
|
|
describe 'when calling validate_array from puppet' do
|
|
|
|
|
|
|
|
%w{ true false }.each do |the_string|
|
|
|
|
it "should not compile when #{the_string} is a string" do
|
|
|
|
Puppet[:code] = "validate_array('#{the_string}')"
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
|
2011-08-04 00:51:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not compile when #{the_string} is a bare word" do
|
|
|
|
Puppet[:code] = "validate_array(#{the_string})"
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
|
2011-08-04 00:51:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should compile when multiple array arguments are passed" do
|
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
$foo = [ ]
|
|
|
|
$bar = [ 'one', 'two' ]
|
|
|
|
validate_array($foo, $bar)
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
scope.compiler.compile
|
2011-08-04 00:51:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not compile when an undef variable is passed" do
|
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
$foo = undef
|
|
|
|
validate_array($foo)
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
|
2011-08-04 00:51:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|