]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/delete_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / delete_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the delete function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("delete")).to eq("function_delete")
9   end
10
11   it "should raise a ParseError if there are fewer than 2 arguments" do
12     expect { scope.function_delete([]) }.to(raise_error(Puppet::ParseError))
13   end
14
15   it "should raise a ParseError if there are greater than 2 arguments" do
16     expect { scope.function_delete([[], 'foo', 'bar']) }.to(raise_error(Puppet::ParseError))
17   end
18
19   it "should raise a TypeError if a number is passed as the first argument" do
20     expect { scope.function_delete([1, 'bar']) }.to(raise_error(TypeError))
21   end
22
23   it "should delete all instances of an element from an array" do
24     result = scope.function_delete([['a', 'b', 'c', 'b'], 'b'])
25     expect(result).to(eq(['a', 'c']))
26   end
27
28   it "should delete all instances of a substring from a string" do
29     result = scope.function_delete(['foobarbabarz', 'bar'])
30     expect(result).to(eq('foobaz'))
31   end
32
33   it "should delete a key from a hash" do
34     result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, 'b'])
35     expect(result).to(eq({'a' => 1, 'c' => 3}))
36   end
37
38   it 'should accept an array of items to delete' do
39     result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, ['b', 'c']])
40     expect(result).to(eq({'a' => 1}))
41   end
42
43   it "should not change origin array passed as argument" do
44     origin_array = ['a', 'b', 'c', 'd']
45     result = scope.function_delete([origin_array, 'b'])
46     expect(origin_array).to(eq(['a', 'b', 'c', 'd']))
47   end
48
49   it "should not change the origin string passed as argument" do
50     origin_string = 'foobarbabarz'
51     result = scope.function_delete([origin_string, 'bar'])
52     expect(origin_string).to(eq('foobarbabarz'))
53   end
54
55   it "should not change origin hash passed as argument" do
56     origin_hash = {'a' => 1, 'b' => 2, 'c' => 3}
57     result = scope.function_delete([origin_hash, 'b'])
58     expect(origin_hash).to(eq({'a' => 1, 'b' => 2, 'c' => 3}))
59   end
60
61 end