- describe 'when calling validate_numeric from puppet only with input' do
- %w{ 1 -1 1.0 -1.0 }.each do |the_number|
- it "should compile when #{the_number} is an encapsulated numeric" do
- Puppet[:code] = "validate_numeric('#{the_number}')"
- scope.compiler.compile
- end
- it "should compile when #{the_number} is a bare numeric" do
- Puppet[:code] = "validate_numeric(#{the_number})"
- scope.compiler.compile
- end
- end
-
- %w{ [1,2,3,4,5] ['1','2','3','4','5'] [1.1,2.2,3.3,4.4,5.5] ['1.1','2.2','3.3','4.4','5.5'] }.each do |the_number|
- it "should compile when multiple Numeric arguments are passed in an Array" do
- Puppet[:code] = "validate_numeric(#{the_number})"
- scope.compiler.compile
- end
- end
-
- %w{ true false iAmAString 1test }.each do |the_number|
- it "should not compile when #{the_number} is in a string" do
- Puppet[:code] = "validate_numeric('#{the_number}')"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/)
- end
-
- it "should not compile when #{the_number} is a bare word" do
- Puppet[:code] = "validate_numeric(#{the_number})"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/)
- end
- end
-
- it "should not compile when a Numeric is part of a larger String" do
- Puppet[:code] = "validate_numeric('1.0 test')"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/)
- end
-
- it "should not compile when an Array with a non-Numeric value is passed" do
- Puppet[:code] = "validate_numeric([1, 'test'])"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /at array position 1 to be a Numeric/)
- end
-
- it "should not compile when a Hash is passed" do
- Puppet[:code] = "validate_numeric({ 1 => 2 })"
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric or Array/)
- end
-
- it "should not compile when an explicitly undef variable is passed" do
- Puppet[:code] = <<-'ENDofPUPPETcode'
- $foo = undef
- validate_numeric($foo)
- ENDofPUPPETcode
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/)
- end
-
- it "should not compile when an undefined variable is passed" do
- Puppet[:code] = 'validate_numeric($foobarbazishouldnotexist)'
- expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/)
- end