]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/has_key_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / has_key_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe Puppet::Parser::Functions.function(:has_key) do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
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()'
11       expect {
12         scope.compiler.compile
13       }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
14     end
15
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')"
19       expect {
20         scope.compiler.compile
21       }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
22     end
23
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')"
27       expect {
28         scope.compiler.compile
29       }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/)
30     end
31   end
32
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
36     end
37
38     it 'should detect existing keys' do
39       expect(scope.function_has_key([{'one' => 1}, 'two'])).to be_falsey
40     end
41   end
42 end