forked from pusewicz/sonia
/
config_spec.rb
89 lines (70 loc) · 1.91 KB
/
config_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'spec_helper'
require 'sonia/config'
describe Sonia::Config do
describe "#new" do
let(:data) {{
:name => 'Sonia',
:nested => {
:one => 1,
:two => 2
}
}}
subject { Sonia::Config.new(data) }
its(:name) { should == 'Sonia' }
its(:nested) { should be_kind_of Sonia::Config }
it "has nested data" do
subject.nested.one.should == 1
subject.nested.two.should == 2
end
end
describe "#[]" do
let(:data) {{ :name => 'Sonia' }}
subject { Sonia::Config.new(data) }
it "returns same data" do
subject.name.should == 'Sonia'
subject[:name].should == 'Sonia'
subject["name"].should == 'Sonia'
end
end
describe "#[]=" do
let(:data) {{ :name => 'Sonia' }}
subject { Sonia::Config.new(data) }
it "allows updating data" do
subject.name.should == 'Sonia'
subject[:name] = "Piotr"
subject.name.should == 'Piotr'
subject[:name].should == 'Piotr'
subject["name"].should == 'Piotr'
subject["name"] = "John"
subject.name.should == 'John'
subject[:name].should == 'John'
subject["name"].should == 'John'
end
end
describe "#each" do
let(:data) {{ :name => 'Sonia', :age => 21 }}
subject { Sonia::Config.new(data) }
it "returns enumerator" do
subject.each.should be_kind_of(Enumerator)
end
it "allows to iterate over keys" do
hash = {}
subject.each do |k, v|
hash[k] = v
end
hash.keys.size.should == 2
hash.values.size.should == 2
hash.keys.should include(:name)
hash.keys.should include(:age)
hash.values.should include(21)
hash.values.should include('Sonia')
end
end
describe "#to_hash" do
let(:data) {{ "age" => 21 }}
subject { Sonia::Config.new(data) }
it "returns whole config data" do
subject.to_hash.should == { :age => 21 }
end
end
end