]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/delete_undef_values_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / delete_undef_values_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the delete_undef_values function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("delete_undef_values")).to eq("function_delete_undef_values")
9   end
10
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))
13   end
14
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))
18   end
19
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']))
23   end
24
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'}))
28   end
29
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']))
34   end
35
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' }))
40   end
41 end