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