Mercurial > repos > other > Puppet
annotate 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 |
rev | line source |
---|---|
37 | 1 require 'spec_helper' |
2 | |
272 | 3 describe 'loadyaml' do |
4 it { is_expected.not_to eq(nil) } | |
5 it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) } | |
6 | |
7 context 'when a non-existing file is specified' do | |
8 let(:filename) { '/tmp/doesnotexist' } | |
37 | 9 |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
10 it "'default' => 'value'" do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
11 expect(File).to receive(:exists?).with(filename).and_return(false).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
12 expect(YAML).to receive(:load_file).never |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
13 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') |
272 | 14 end |
37 | 15 end |
16 | |
272 | 17 context 'when an existing file is specified' do |
18 let(:filename) { '/tmp/doesexist' } | |
19 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } | |
20 | |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
21 it "returns 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'" do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
22 expect(File).to receive(:exists?).with(filename).and_return(true).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
23 expect(YAML).to receive(:load_file).with(filename).and_return(data).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
24 is_expected.to run.with_params(filename).and_return(data) |
272 | 25 end |
37 | 26 end |
27 | |
272 | 28 context 'when the file could not be parsed' do |
29 let(:filename) { '/tmp/doesexist' } | |
30 | |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
31 it 'filename /tmp/doesexist' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
32 expect(File).to receive(:exists?).with(filename).and_return(true).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
33 allow(YAML).to receive(:load_file).with(filename).once.and_raise(StandardError, 'Something terrible have happened!') |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
34 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') |
37 | 35 end |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
36 end |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
37 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
38 context 'when an existing URL is specified' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
39 let(:filename) { 'https://example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
40 let(:basic_auth) { { :http_basic_authentication => ['', ''] } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
41 let(:yaml) { 'Dummy YAML' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
42 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
43 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
44 it { |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
45 expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
46 expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
47 is_expected.to run.with_params(filename).and_return(data) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
48 } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
49 end |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
50 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
51 context 'when an existing URL (with username and password) is specified' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
52 let(:filename) { 'https://user1:pass1@example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
53 let(:url_no_auth) { 'https://example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
54 let(:basic_auth) { { :http_basic_authentication => ['user1', 'pass1'] } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
55 let(:yaml) { 'Dummy YAML' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
56 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
57 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
58 it { |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
59 expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(yaml) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
60 expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
61 is_expected.to run.with_params(filename).and_return(data) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
62 } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
63 end |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
64 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
65 context 'when an existing URL (with username) is specified' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
66 let(:filename) { 'https://user1@example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
67 let(:url_no_auth) { 'https://example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
68 let(:basic_auth) { { :http_basic_authentication => ['user1', ''] } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
69 let(:yaml) { 'Dummy YAML' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
70 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
71 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
72 it { |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
73 expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(yaml) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
74 expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
75 is_expected.to run.with_params(filename).and_return(data) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
76 } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
77 end |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
78 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
79 context 'when an existing URL could not be parsed, with default specified' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
80 let(:filename) { 'https://example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
81 let(:basic_auth) { { :http_basic_authentication => ['', ''] } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
82 let(:yaml) { 'Dummy YAML' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
83 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
84 it { |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
85 expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
86 expect(YAML).to receive(:safe_load).with(yaml).and_raise StandardError, 'Cannot parse data' |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
87 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
88 } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
89 end |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
90 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
91 context 'when a URL does not exist, with default specified' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
92 let(:filename) { 'https://example.local/myhash.yaml' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
93 let(:basic_auth) { { :http_basic_authentication => ['', ''] } } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
94 let(:yaml) { 'Dummy YAML' } |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
95 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
96 it { |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
97 expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_raise OpenURI::HTTPError, '404 File not Found' |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
98 is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
99 } |
37 | 100 end |
101 end |