1 #! /usr/bin/env ruby -S rspec
5 describe "the count function" do
6 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
9 expect(Puppet::Parser::Functions.function("count")).to eq("function_count")
12 it "should raise a ArgumentError if there is more than 2 arguments" do
13 expect { scope.function_count(['foo', 'bar', 'baz']) }.to( raise_error(ArgumentError))
16 it "should be able to count arrays" do
17 expect(scope.function_count([["1","2","3"]])).to(eq(3))
20 it "should be able to count matching elements in arrays" do
21 expect(scope.function_count([["1", "2", "2"], "2"])).to(eq(2))
24 it "should not count nil or empty strings" do
25 expect(scope.function_count([["foo","bar",nil,""]])).to(eq(2))
28 it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do
29 expect(scope.function_count([["foo",:undef,:undef]])).to eq(1)