|
| 1 | +#! /usr/bin/env ruby -S rspec |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +describe Puppet::Parser::Functions.function(:has_element) do |
| 5 | + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } |
| 6 | + |
| 7 | + describe 'when calling has_element from puppet' do |
| 8 | + it "should not compile when no arguments are passed" do |
| 9 | + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ |
| 10 | + Puppet[:code] = '$x = has_element()' |
| 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 | + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ |
| 18 | + Puppet[:code] = "$x = has_element('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 an Array" do |
| 25 | + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ |
| 26 | + Puppet[:code] = "$x = has_element('foo', 'bar')" |
| 27 | + expect { |
| 28 | + scope.compiler.compile |
| 29 | + }.to raise_error(Puppet::ParseError, /expects the first argument to be an array/) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe 'when calling the function has_element from a scope instance' do |
| 34 | + it 'should detect existing elements' do |
| 35 | + scope.function_has_element([['one'], 'one']).should be_true |
| 36 | + end |
| 37 | + |
| 38 | + it 'should detect existing elements' do |
| 39 | + scope.function_has_element([['one'], 'two']).should be_false |
| 40 | + end |
| 41 | + end |
| 42 | +end |
0 commit comments