Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / delete_regex_spec.rb
1 require 'spec_helper'
2
3 describe 'delete_regex' do
4   it { is_expected.not_to eq(nil) }
5   it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
6   it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
7   it { is_expected.to run.with_params([], 'two') }
8   it { is_expected.to run.with_params({}, 'two') }
9   it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
10   it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError, %r{First argument must be an Array, Hash, or String}) }
11
12   describe 'deleting from an array' do
13     it { is_expected.to run.with_params([], '').and_return([]) }
14     it { is_expected.to run.with_params([], 'two').and_return([]) }
15     it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
16     it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
17     it { is_expected.to run.with_params(['one', 'two', 'three'], '^t.*').and_return(['one']) }
18     it { is_expected.to run.with_params(['ab', 'b', 'c', 'b'], 'b').and_return(['ab', 'c']) }
19     it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
20     it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
21     it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
22     it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
23     it { is_expected.to run.with_params(['abracadabra'], 'abr').and_return(['abracadabra']) }
24     it { is_expected.to run.with_params(['abracadabra'], '^.*jimbob.*$').and_return(['abracadabra']) }
25   end
26
27   describe 'deleting from an array' do
28     it { is_expected.to run.with_params({}, '').and_return({}) }
29     it { is_expected.to run.with_params({}, 'key').and_return({}) }
30     it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
31     it {
32       is_expected.to run \
33         .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
34         .and_return('key1' => 'value1', 'key3' => 'value3')
35     }
36     it {
37       is_expected.to run \
38         .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, ['key1', 'key2']) \
39         .and_return('key3' => 'value3')
40     }
41   end
42
43   it 'leaves the original array intact' do
44     argument1 = ['one', 'two', 'three']
45     original1 = argument1.dup
46     subject.execute(argument1, 'two')
47     expect(argument1).to eq(original1)
48   end
49   it 'leaves the original hash intact' do
50     argument1 = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
51     original1 = argument1.dup
52     subject.execute(argument1, 'key2')
53     expect(argument1).to eq(original1)
54   end
55 end