Mercurial > repos > other > Puppet
comparison modules/stdlib/spec/functions/loadyaml_spec.rb @ 275:d9352a684e62
Mass update of modules to remove deprecation warnings
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Jan 2020 11:36:07 +0000 |
parents | c42fb28cff86 |
children |
comparison
equal
deleted
inserted
replaced
274:b2571c28fc27 | 275:d9352a684e62 |
---|---|
5 it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) } | 5 it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) } |
6 | 6 |
7 context 'when a non-existing file is specified' do | 7 context 'when a non-existing file is specified' do |
8 let(:filename) { '/tmp/doesnotexist' } | 8 let(:filename) { '/tmp/doesnotexist' } |
9 | 9 |
10 before(:each) do | 10 it "'default' => 'value'" do |
11 File.expects(:exists?).with(filename).returns(false).once | 11 expect(File).to receive(:exists?).with(filename).and_return(false).once |
12 YAML.expects(:load_file).never | 12 expect(YAML).to receive(:load_file).never |
13 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') | |
13 end | 14 end |
14 it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') } | |
15 it { is_expected.to run.with_params(filename, 'đẽƒằưļŧ' => '٧ẵłựέ').and_return('đẽƒằưļŧ' => '٧ẵłựέ') } | |
16 it { is_expected.to run.with_params(filename, 'デフォルト' => '値').and_return('デフォルト' => '値') } | |
17 end | 15 end |
18 | 16 |
19 context 'when an existing file is specified' do | 17 context 'when an existing file is specified' do |
20 let(:filename) { '/tmp/doesexist' } | 18 let(:filename) { '/tmp/doesexist' } |
21 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } | 19 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } |
22 | 20 |
23 before(:each) do | 21 it "returns 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'" do |
24 File.expects(:exists?).with(filename).returns(true).once | 22 expect(File).to receive(:exists?).with(filename).and_return(true).once |
25 YAML.expects(:load_file).with(filename).returns(data).once | 23 expect(YAML).to receive(:load_file).with(filename).and_return(data).once |
24 is_expected.to run.with_params(filename).and_return(data) | |
26 end | 25 end |
27 it { is_expected.to run.with_params(filename).and_return(data) } | |
28 end | 26 end |
29 | 27 |
30 context 'when the file could not be parsed' do | 28 context 'when the file could not be parsed' do |
31 let(:filename) { '/tmp/doesexist' } | 29 let(:filename) { '/tmp/doesexist' } |
32 | 30 |
33 before(:each) do | 31 it 'filename /tmp/doesexist' do |
34 File.expects(:exists?).with(filename).returns(true).once | 32 expect(File).to receive(:exists?).with(filename).and_return(true).once |
35 YAML.stubs(:load_file).with(filename).once.raises StandardError, 'Something terrible have happened!' | 33 allow(YAML).to receive(:load_file).with(filename).once.and_raise(StandardError, 'Something terrible have happened!') |
34 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') | |
36 end | 35 end |
37 it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') } | 36 end |
37 | |
38 context 'when an existing URL is specified' do | |
39 let(:filename) { 'https://example.local/myhash.yaml' } | |
40 let(:basic_auth) { { :http_basic_authentication => ['', ''] } } | |
41 let(:yaml) { 'Dummy YAML' } | |
42 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } | |
43 | |
44 it { | |
45 expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml) | |
46 expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once | |
47 is_expected.to run.with_params(filename).and_return(data) | |
48 } | |
49 end | |
50 | |
51 context 'when an existing URL (with username and password) is specified' do | |
52 let(:filename) { 'https://user1:pass1@example.local/myhash.yaml' } | |
53 let(:url_no_auth) { 'https://example.local/myhash.yaml' } | |
54 let(:basic_auth) { { :http_basic_authentication => ['user1', 'pass1'] } } | |
55 let(:yaml) { 'Dummy YAML' } | |
56 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } | |
57 | |
58 it { | |
59 expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(yaml) | |
60 expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once | |
61 is_expected.to run.with_params(filename).and_return(data) | |
62 } | |
63 end | |
64 | |
65 context 'when an existing URL (with username) is specified' do | |
66 let(:filename) { 'https://user1@example.local/myhash.yaml' } | |
67 let(:url_no_auth) { 'https://example.local/myhash.yaml' } | |
68 let(:basic_auth) { { :http_basic_authentication => ['user1', ''] } } | |
69 let(:yaml) { 'Dummy YAML' } | |
70 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } | |
71 | |
72 it { | |
73 expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(yaml) | |
74 expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once | |
75 is_expected.to run.with_params(filename).and_return(data) | |
76 } | |
77 end | |
78 | |
79 context 'when an existing URL could not be parsed, with default specified' do | |
80 let(:filename) { 'https://example.local/myhash.yaml' } | |
81 let(:basic_auth) { { :http_basic_authentication => ['', ''] } } | |
82 let(:yaml) { 'Dummy YAML' } | |
83 | |
84 it { | |
85 expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml) | |
86 expect(YAML).to receive(:safe_load).with(yaml).and_raise StandardError, 'Cannot parse data' | |
87 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') | |
88 } | |
89 end | |
90 | |
91 context 'when a URL does not exist, with default specified' do | |
92 let(:filename) { 'https://example.local/myhash.yaml' } | |
93 let(:basic_auth) { { :http_basic_authentication => ['', ''] } } | |
94 let(:yaml) { 'Dummy YAML' } | |
95 | |
96 it { | |
97 expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_raise OpenURI::HTTPError, '404 File not Found' | |
98 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') | |
99 } | |
38 end | 100 end |
39 end | 101 end |