2012-07-20 01:14:37 +02:00
|
|
|
#! /usr/bin/env/ruby -S rspec
|
2011-06-03 20:41:20 +02:00
|
|
|
|
2012-07-20 01:14:37 +02:00
|
|
|
require 'spec_helper'
|
2011-06-03 20:41:20 +02:00
|
|
|
|
|
|
|
describe Puppet::Parser::Functions.function(:validate_bool) do
|
2012-07-20 01:14:37 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetSeams.parser_scope }
|
2011-06-03 20:41:20 +02:00
|
|
|
describe 'when calling validate_bool from puppet' do
|
2011-06-03 20:56:02 +02:00
|
|
|
|
|
|
|
%w{ true false }.each do |the_string|
|
|
|
|
|
|
|
|
it "should not compile when #{the_string} is a string" do
|
|
|
|
Puppet[:code] = "validate_bool('#{the_string}')"
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
|
2011-06-03 20:56:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should compile when #{the_string} is a bare word" do
|
|
|
|
Puppet[:code] = "validate_bool(#{the_string})"
|
2012-07-20 01:14:37 +02:00
|
|
|
scope.compiler.compile
|
2011-06-03 20:56:02 +02:00
|
|
|
end
|
|
|
|
|
2011-06-03 20:41:20 +02:00
|
|
|
end
|
2011-06-03 20:56:02 +02:00
|
|
|
|
2011-06-03 20:41:20 +02:00
|
|
|
it "should not compile when an arbitrary string is passed" do
|
|
|
|
Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
|
2011-06-03 20:41:20 +02:00
|
|
|
end
|
2011-06-03 20:56:02 +02:00
|
|
|
|
2011-06-03 20:41:20 +02:00
|
|
|
it "should not compile when no arguments are passed" do
|
|
|
|
Puppet[:code] = 'validate_bool()'
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
|
2011-06-03 20:41:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should compile when multiple boolean arguments are passed" do
|
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
$foo = true
|
|
|
|
$bar = false
|
|
|
|
validate_bool($foo, $bar, true, false)
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
scope.compiler.compile
|
2011-06-03 20:41:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should compile when multiple boolean arguments are passed" do
|
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
$foo = true
|
|
|
|
$bar = false
|
|
|
|
validate_bool($foo, $bar, true, false, 'jeff')
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
|
2011-06-03 20:41:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|