configurator_spec.rb
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
describe Configurator do
before(:each) do
allow(ENV).to receive(:[]).and_return(nil)
allow(ENV).to receive(:[]).with('VARONE').and_return('zoom')
allow(ENV).to receive(:[]).with('VARTHREE').and_return('zipp')
end
it 'takes the first existing env, second item' do
result = Configurator.run({ two: ['VARTWO', 'VARTHREE'] })
expect(result.two).to eq('zipp')
end
it 'takes the first existing env, first item' do
result = Configurator.run({ three: ['VARTHREE', 'VARONE'] })
expect(result.three).to eq('zipp')
end
it 'provides nothing for missing variables' do
result = Configurator.run({ four: ['VAREIGHTY'] })
expect(result.four).to be_nil
end
it 'overrides existing variables' do
result = Configurator.run({
one: ['VARONE', ->(values) { 'oveRIIIDE' } ]
})
expect(result.one).to eq('oveRIIIDE')
end
it 'overrides can refer to other values' do
result = Configurator.run({
one: ['VARONE', ->(values) { values[:one] } ],
three: ['VARTHREE' ]
})
expect(result.one).to eq('zoom')
end
it 'extracts symbol values' do
allow(ENV).to receive(:[]).with('MYSYMBOL').and_return(':asymbol')
result = Configurator.run({ mysymbol: ['MYSYMBOL'] })
expect(result.mysymbol).to be(:asymbol)
end
it 'extracts array values' do
allow(ENV).to receive(:[]).with('MYARRAY').and_return('[one,two,three]')
result = Configurator.run({ myarray: ['MYARRAY'] })
expect(result.myarray).to eq(['one', 'two', 'three'])
end
it 'extracts booleans' do
allow(ENV).to receive(:[]).with('MYBOOLEAN').and_return('true')
result = Configurator.run({ myboolean: ['MYBOOLEAN'] })
expect(result.myboolean).to be(true)
end
it 'extracts numbers' do
allow(ENV).to receive(:[]).with('MYNUMBER').and_return('0')
result = Configurator.run({ mynumber: ['MYNUMBER'] })
expect(result.mynumber).to be(0)
end
end