1 #! /usr/bin/env ruby -S rspec
4 describe "the delete_undef_values function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("delete_undef_values")).to eq("function_delete_undef_values")
11 it "should raise a ParseError if there is less than 1 argument" do
12 expect { scope.function_delete_undef_values([]) }.to( raise_error(Puppet::ParseError))
15 it "should raise a ParseError if the argument is not Array nor Hash" do
16 expect { scope.function_delete_undef_values(['']) }.to( raise_error(Puppet::ParseError))
17 expect { scope.function_delete_undef_values([nil]) }.to( raise_error(Puppet::ParseError))
20 it "should delete all undef items from Array and only these" do
21 result = scope.function_delete_undef_values([['a',:undef,'c','undef']])
22 expect(result).to(eq(['a','c','undef']))
25 it "should delete all undef items from Hash and only these" do
26 result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}])
27 expect(result).to(eq({'a'=>'A','c'=>'C','d'=>'undef'}))
30 it "should not change origin array passed as argument" do
31 origin_array = ['a',:undef,'c','undef']
32 result = scope.function_delete_undef_values([origin_array])
33 expect(origin_array).to(eq(['a',:undef,'c','undef']))
36 it "should not change origin hash passed as argument" do
37 origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' }
38 result = scope.function_delete_undef_values([origin_hash])
39 expect(origin_hash).to(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' }))