Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / delete_values_spec.rb
1 require 'spec_helper'
2
3 describe 'delete_values' 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(1).and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
7   it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
8   it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
9   describe 'when the first argument is not a hash' do
10     it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError, %r{First argument must be a Hash}) }
11     it { is_expected.to run.with_params('one', 'two').and_raise_error(TypeError, %r{First argument must be a Hash}) }
12     it { is_expected.to run.with_params([], 'two').and_raise_error(TypeError, %r{First argument must be a Hash}) }
13   end
14
15   describe 'when deleting from a hash' do
16     it { is_expected.to run.with_params({}, 'value').and_return({}) }
17     it {
18       is_expected.to run \
19         .with_params({ 'key1' => 'value1' }, 'non-existing value') \
20         .and_return('key1' => 'value1')
21     }
22     it {
23       is_expected.to run \
24         .with_params({ 'ҝếỵ1 ' => 'νâĺūẹ1', 'ҝếỵ2' => 'value to delete' }, 'value to delete') \
25         .and_return('ҝếỵ1 ' => 'νâĺūẹ1')
26     }
27     it {
28       is_expected.to run \
29         .with_params({ 'key1' => 'value1', 'key2' => 'νǎŀữ℮ ťớ đêłểťė' }, 'νǎŀữ℮ ťớ đêłểťė') \
30         .and_return('key1' => 'value1')
31     }
32     it {
33       is_expected.to run \
34         .with_params({ 'key1' => 'value1', 'key2' => 'value to delete', 'key3' => 'value to delete' }, 'value to delete') \
35         .and_return('key1' => 'value1')
36     }
37   end
38
39   it 'leaves the original argument intact' do
40     argument = { 'key1' => 'value1', 'key2' => 'value2' }
41     original = argument.dup
42     _result = subject.execute(argument, 'value2')
43     expect(argument).to eq(original)
44   end
45 end