forked from 3scale/3scale_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration_spec.rb
66 lines (55 loc) · 1.69 KB
/
configuration_spec.rb
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
62
63
64
65
66
RSpec.describe ThreeScaleToolbox::Configuration do
include_context :temp_dir
let(:config_file) { File.join(tmp_dir, '.3scalerc') }
subject { described_class.new config_file }
context '#data' do
context 'non existing file' do
let(:config_file) { File.join(tmp_dir, 'non_existing_file') }
it 'returns nothing' do
expect(subject.data(:some_key)).to be_nil
end
end
context 'empty file' do
before :each do
File.open(config_file, 'w') {}
end
it 'returns nothing' do
expect(subject.data(:some_key)).to be_nil
end
end
context 'invalid data' do
before :each do
File.open(config_file, 'w') { |f| f.write('<tag1>somedata</tag1>') }
end
it 'raises error' do
expect { subject.data(:some_key) }.to raise_error(PStore::Error)
end
end
context 'valid data' do
before :each do
config = described_class.new config_file
config.update(:some_key) { 'some_data' }
end
it 'finds on key' do
expect(subject.data(:some_key)).to eq('some_data')
end
it 'nil on wrong key' do
expect(subject.data(:wrong_key)).to be_nil
end
end
end
context '#update' do
context 'file with data' do
before :each do
config = described_class.new config_file
config.update(:some_key) { 'some_data' }
end
it 'updates gets persisted' do
expect(subject.data(:some_key)).to eq('some_data')
subject.update(:some_key) { 'other_data' }
expect(subject.data(:some_key)).to eq('other_data')
expect(described_class.new(config_file).data(:some_key)).to eq('other_data')
end
end
end
end