- describe 'when calling validate_numeric from puppet with input, a maximum and a minimum' do
- it "should not compile when a minimum larger than maximum is passed" do
- Puppet[:code] = "validate_numeric(1,1,2)"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /second argument to be larger than third argument/)
- end
-
- max = 10
- min = -10
- %w{ 1 -1 }.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_numeric(#{the_number},#{max},#{min})"
- scope.compiler.compile
- end
- end
-
- it "should compile when a Numeric is equal the minimum" do
- Puppet[:code] = "validate_numeric(#{min},#{max},#{min})"
- scope.compiler.compile
- end
-
- it "should compile when a Numeric is equal the minimum and maximum" do
- Puppet[:code] = "validate_numeric(#{max},#{max},#{max})"
- scope.compiler.compile
- end
-
- it "should compile when an empty maximum is passed and the Numeric is greater than the minimum" do
- Puppet[:code] = "validate_numeric(#{max}.1,'',#{min})"
- scope.compiler.compile
- end
- it "should compile when an explicitly undefined maximum is passed and the Numeric is greater than the minimum" do
- Puppet[:code] = "validate_numeric(#{max}.1,undef,#{min})"
- scope.compiler.compile
- end
- it "should compile when an explicitly undefined variable is passed for maximum and the Numeric is greater than the minimum" do
- Puppet[:code] = <<-"ENDofPUPPETcode"
- $foo = undef
- validate_numeric(#{max}.1, $foo, #{min})
- ENDofPUPPETcode
- scope.compiler.compile
- end
- it "should not compile when no maximum value is given and the Numeric is greater than the minimum" do
- Puppet[:code] = "validate_numeric(#{max}.1,,#{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_numeric(#{min-1.0},#{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.0','1','2','3','4','5','10.0'] }.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_numeric(#{the_number},#{max},#{min})"
- scope.compiler.compile
- end
- end
-
- it "should not compile when an element of an Array [#{min-1.1},1,2,3,4,5,10.0] is lower than a minimum of #{min}" do
- Puppet[:code] = "validate_numeric([#{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