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) }
|
---|
6 | it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
|
---|
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) }
|
---|
10 | it { is_expected.to run.with_params([], 'two', 'three', 'four').and_raise_error(Puppet::ParseError) }
|
---|
11 | it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
|
---|
12 |
|
---|
13 | describe 'deleting from an array' do
|
---|
14 | it { is_expected.to run.with_params([], '').and_return([]) }
|
---|
15 | it { is_expected.to run.with_params([], 'two').and_return([]) }
|
---|
16 | it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
|
---|
17 | it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
|
---|
18 | it { is_expected.to run.with_params(['one', 'two', 'three'], '^t.*').and_return(['one']) }
|
---|
19 | it { is_expected.to run.with_params(['ab', 'b', 'c', 'b'], 'b').and_return(['ab', 'c']) }
|
---|
20 | it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
|
---|
21 | it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
|
---|
22 | it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
|
---|
23 | it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
|
---|
24 | it { is_expected.to run.with_params(['abracadabra'], 'abr').and_return(['abracadabra']) }
|
---|
25 | it { is_expected.to run.with_params(['abracadabra'], '^.*jimbob.*$').and_return(['abracadabra']) }
|
---|
26 | end
|
---|
27 |
|
---|
28 | describe 'deleting from an array' do
|
---|
29 | it { is_expected.to run.with_params({}, '').and_return({}) }
|
---|
30 | it { is_expected.to run.with_params({}, 'key').and_return({}) }
|
---|
31 | it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) }
|
---|
32 | it { is_expected.to run \
|
---|
33 | .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, 'key2') \
|
---|
34 | .and_return( {'key1' => 'value1', 'key3' => 'value3'})
|
---|
35 | }
|
---|
36 | it { is_expected.to run \
|
---|
37 | .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
|
---|
38 | .and_return( {'key3' => 'value3'})
|
---|
39 | }
|
---|
40 | end
|
---|
41 |
|
---|
42 | it "should leave the original array intact" do
|
---|
43 | argument1 = ['one','two','three']
|
---|
44 | original1 = argument1.dup
|
---|
45 | subject.call([argument1,'two'])
|
---|
46 | expect(argument1).to eq(original1)
|
---|
47 | end
|
---|
48 | it "should leave the original hash intact" do
|
---|
49 | argument1 = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}
|
---|
50 | original1 = argument1.dup
|
---|
51 | subject.call([argument1,'key2'])
|
---|
52 | expect(argument1).to eq(original1)
|
---|
53 | end
|
---|
54 | end
|
---|