- it "should compile when an Integer is equal the minimum and maximum" do
- Puppet[:code] = "validate_integer(#{max},#{max},#{max})"
- scope.compiler.compile
- end
-
- it "should compile when an empty maximum is passed and the Integer is greater than the minimum" do
- Puppet[:code] = "validate_integer(#{max},'',#{min})"
- scope.compiler.compile
- end
- it "should compile when an explicitly undefined maximum is passed and the Integer is greater than the minimum" do
- Puppet[:code] = "validate_integer(#{max},undef,#{min})"
- scope.compiler.compile
- end
- it "should compile when an explicitly undefined variable is passed for maximum and the Integer is greater than the minimum" do
- Puppet[:code] = <<-"ENDofPUPPETcode"
- $foo = undef
- validate_integer(#{max}, $foo, #{min})
- ENDofPUPPETcode
- scope.compiler.compile
- end
- it "should not compile when no maximum value is given and the Integer is greater than the minimum" do
- Puppet[:code] = "validate_integer(#{max},,#{min})"
- expect { scope.compiler.compile }.to raise_error(Puppet::Error, /Syntax error at ','/)
- end
-
- it "should not compile when #{min-1} is lower than a minimum of #{min}" do
- Puppet[:code] = "validate_integer(#{min-1},#{max},#{min})"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be greater or equal to/)
- end
-
- %w{ [-10,1,2,3,4,5,10] ['-10','1','2','3','4','5','10'] }.each do |the_number|
- it "should compile when each element of #{the_number} is within a range from #{min} to #{max}" do
- Puppet[:code] = "validate_integer(#{the_number},#{max},#{min})"
- scope.compiler.compile
- end
- end
-
- it "should not compile when an element of an Array [#{min-1},1,2,3,4,5,10] is lower than a minimum of #{min}" do
- Puppet[:code] = "validate_integer([#{min-1},1,2,3,4,5,10],#{max},#{min})"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be greater or equal to/)
- end
-
- %w{ true false iAmAString 1test 7.0 -7.0 }.each do |the_min|
- it "should not compile when a non-Integer minimum #{the_min}, encapsulated in a String, is passed" do
- Puppet[:code] = "validate_integer(1,#{max},'#{the_min}')"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/)
- end
-
- it "should not compile when a non-Integer minimum #{the_min} bare word is passed" do
- Puppet[:code] = "validate_integer(1,#{max},#{the_min})"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/)
- end
- end