1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:has_key) do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 describe 'when calling has_key from puppet' do
8 it "should not compile when no arguments are passed" do
9 skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
10 Puppet[:code] = '$x = has_key()'
12 scope.compiler.compile
13 }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
16 it "should not compile when 1 argument is passed" do
17 skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
18 Puppet[:code] = "$x = has_key('foo')"
20 scope.compiler.compile
21 }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
24 it "should require the first value to be a Hash" do
25 skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
26 Puppet[:code] = "$x = has_key('foo', 'bar')"
28 scope.compiler.compile
29 }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/)
33 describe 'when calling the function has_key from a scope instance' do
34 it 'should detect existing keys' do
35 expect(scope.function_has_key([{'one' => 1}, 'one'])).to be_truthy
38 it 'should detect existing keys' do
39 expect(scope.function_has_key([{'one' => 1}, 'two'])).to be_falsey