| 1 | require 'spec_helper'
|
|---|
| 2 |
|
|---|
| 3 | describe 'delete' 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', 'three').and_raise_error(Puppet::ParseError) }
|
|---|
| 8 | it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
|
|---|
| 9 |
|
|---|
| 10 | describe 'deleting from an array' do
|
|---|
| 11 | it { is_expected.to run.with_params([], '').and_return([]) }
|
|---|
| 12 | it { is_expected.to run.with_params([], 'two').and_return([]) }
|
|---|
| 13 | it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
|
|---|
| 14 | it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
|
|---|
| 15 | it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
|
|---|
| 16 | it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
|
|---|
| 17 | it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
|
|---|
| 18 | it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
|
|---|
| 19 | it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) }
|
|---|
| 20 | end
|
|---|
| 21 |
|
|---|
| 22 | describe 'deleting from a string' do
|
|---|
| 23 | it { is_expected.to run.with_params('', '').and_return('') }
|
|---|
| 24 | it { is_expected.to run.with_params('bar', '').and_return('bar') }
|
|---|
| 25 | it { is_expected.to run.with_params('', 'bar').and_return('') }
|
|---|
| 26 | it { is_expected.to run.with_params('bar', 'bar').and_return('') }
|
|---|
| 27 | it { is_expected.to run.with_params('barbar', 'bar').and_return('') }
|
|---|
| 28 | it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') }
|
|---|
| 29 | it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') }
|
|---|
| 30 | it { is_expected.to run.with_params('foobarbabarz', ['foo', 'bar']).and_return('baz') }
|
|---|
| 31 | # this is so sick
|
|---|
| 32 | it { is_expected.to run.with_params('barfoobar', ['barbar', 'foo']).and_return('barbar') }
|
|---|
| 33 | it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') }
|
|---|
| 34 | end
|
|---|
| 35 |
|
|---|
| 36 | describe 'deleting from an array' do
|
|---|
| 37 | it { is_expected.to run.with_params({}, '').and_return({}) }
|
|---|
| 38 | it { is_expected.to run.with_params({}, 'key').and_return({}) }
|
|---|
| 39 | it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) }
|
|---|
| 40 | it { is_expected.to run \
|
|---|
| 41 | .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, 'key2') \
|
|---|
| 42 | .and_return( {'key1' => 'value1', 'key3' => 'value3'})
|
|---|
| 43 | }
|
|---|
| 44 | it { is_expected.to run \
|
|---|
| 45 | .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
|
|---|
| 46 | .and_return( {'key3' => 'value3'})
|
|---|
| 47 | }
|
|---|
| 48 | end
|
|---|
| 49 |
|
|---|
| 50 | it "should leave the original array intact" do
|
|---|
| 51 | argument1 = ['one','two','three']
|
|---|
| 52 | original1 = argument1.dup
|
|---|
| 53 | result = subject.call([argument1,'two'])
|
|---|
| 54 | expect(argument1).to eq(original1)
|
|---|
| 55 | end
|
|---|
| 56 | it "should leave the original string intact" do
|
|---|
| 57 | argument1 = 'onetwothree'
|
|---|
| 58 | original1 = argument1.dup
|
|---|
| 59 | result = subject.call([argument1,'two'])
|
|---|
| 60 | expect(argument1).to eq(original1)
|
|---|
| 61 | end
|
|---|
| 62 | it "should leave the original hash intact" do
|
|---|
| 63 | argument1 = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}
|
|---|
| 64 | original1 = argument1.dup
|
|---|
| 65 | result = subject.call([argument1,'key2'])
|
|---|
| 66 | expect(argument1).to eq(original1)
|
|---|
| 67 | end
|
|---|
| 68 | end
|
|---|