annotate modules/stdlib/spec/functions/try_get_value_spec.rb @ 320:99e3ca448d55

Fix Remi PHP on CentOS 8 It uses the new "modules" approach, so we need to use a new package provider They also use different signing keys
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 Mar 2020 10:58:00 +0000
parents d9352a684e62
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 require 'spec_helper'
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 describe 'try_get_value' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 let(:data) do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 'a' => {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 'g' => '2',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 'e' => [
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 'f0',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 'f1',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 'x' => {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 'y' => 'z',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 },
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 },
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 'f3',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 ],
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 },
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 'b' => true,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 'c' => false,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 'd' => '1',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 context 'with single values' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 it 'exists' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 is_expected.not_to eq(nil)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 it 'is able to return a single value' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 is_expected.to run.with_params('test').and_return('test')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 it 'uses the default value if data is a single value and path is present' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 is_expected.to run.with_params('test', 'path', 'default').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 it 'returns default if there is no data' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 is_expected.to run.with_params(nil, nil, 'default').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 it 'is able to use data structures as default values' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 is_expected.to run.with_params('test', 'path', data).and_return(data)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 context 'with structure values' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 it 'is able to extracts a single hash value' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 is_expected.to run.with_params(data, 'd', 'default').and_return('1')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 it 'is able to extract a deeply nested hash value' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 is_expected.to run.with_params(data, 'a/g', 'default').and_return('2')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 it 'returns the default value if the path is not found' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 is_expected.to run.with_params(data, 'missing', 'default').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 it 'returns the default value if the path is too long' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 is_expected.to run.with_params(data, 'a/g/c/d', 'default').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 it 'supports an array index in the path' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 is_expected.to run.with_params(data, 'a/e/1', 'default').and_return('f1')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 it 'returns the default value if an array index is not a number' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 is_expected.to run.with_params(data, 'a/b/c', 'default').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 it 'returns the default value if and index is out of array length' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 is_expected.to run.with_params(data, 'a/e/5', 'default').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 it 'is able to path though both arrays and hashes' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 is_expected.to run.with_params(data, 'a/e/2/x/y', 'default').and_return('z')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 it 'is able to return "true" value: default' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 is_expected.to run.with_params(data, 'b', 'default').and_return(true)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 it 'is able to return "true" value' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 is_expected.to run.with_params(data, 'm', true).and_return(true)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 it 'is able to return "false" value: default' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 is_expected.to run.with_params(data, 'c', 'default').and_return(false)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 it 'is able to return "false" value' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 is_expected.to run.with_params(data, 'm', false).and_return(false)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 it 'returns "nil" if value is not found and no default value is provided' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 is_expected.to run.with_params(data, 'a/1').and_return(nil)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 it 'is able to use a custom path separator' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 is_expected.to run.with_params(data, 'a::g', 'default', '::').and_return('2')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 it 'is able to use a custom path separator: default' do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 is_expected.to run.with_params(data, 'a::c', 'default', '::').and_return('default')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 end
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
107
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
108 it 'is able to throw an error with incorrect params' do
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
109 is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Wrong number of arguments}i)
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
110 end
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 end