Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 159 lines (130 sloc) 4.71 kb
471adcb @binarylogic Complete rewrite, see changelog / readme
authored
1 require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
3 describe "Settingslogic" do
4 it "should access settings" do
e927113 @binarylogic more tests
authored
5 Settings.setting2.should == 5
471adcb @binarylogic Complete rewrite, see changelog / readme
authored
6 end
7
8 it "should access nested settings" do
9 Settings.setting1.setting1_child.should == "saweet"
10 end
11
e927113 @binarylogic more tests
authored
12 it "should access deep nested settings" do
13 Settings.setting1.deep.another.should == "my value"
14 end
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
15
e927113 @binarylogic more tests
authored
16 it "should access extra deep nested settings" do
17 Settings.setting1.deep.child.value.should == 2
18 end
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
19
471adcb @binarylogic Complete rewrite, see changelog / readme
authored
20 it "should enable erb" do
21 Settings.setting3.should == 25
22 end
805df68 more tests; have pinpointed collisions to top-level settings only
Nate Wiger authored
23
471adcb @binarylogic Complete rewrite, see changelog / readme
authored
24 it "should namespace settings" do
25 Settings2.setting1_child.should == "saweet"
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
26 Settings2.deep.another.should == "my value"
27 end
28
29 it "should return the namespace" do
30 Settings.namespace.should be_nil
31 Settings2.namespace.should == 'setting1'
471adcb @binarylogic Complete rewrite, see changelog / readme
authored
32 end
28dc69b @MitinPavel The issue with 'nested keys' was fixed.
MitinPavel authored
33
34 it "should distinguish nested keys" do
ad83a57 @MitinPavel Settings data was changed to clarify specs.
MitinPavel authored
35 Settings.language.haskell.paradigm.should == 'functional'
36 Settings.language.smalltalk.paradigm.should == 'object oriented'
28dc69b @MitinPavel The issue with 'nested keys' was fixed.
MitinPavel authored
37 end
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
38
39 it "should not collide with global methods" do
805df68 more tests; have pinpointed collisions to top-level settings only
Nate Wiger authored
40 Settings3.nested.collides.does.should == 'not either'
77825ec solved Vlad collision finally by proxying top-level accessor to instance
Nate Wiger authored
41 Settings3[:nested] = 'fooey'
42 Settings3[:nested].should == 'fooey'
43 Settings3.nested.should == 'fooey'
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
44 Settings3.collides.does.should == 'not'
45 end
77825ec solved Vlad collision finally by proxying top-level accessor to instance
Nate Wiger authored
46
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
47 it "should raise a helpful error message" do
48 e = nil
49 begin
50 Settings.missing
51 rescue => e
52 e.should be_kind_of Settingslogic::MissingSetting
53 end
54 e.should_not be_nil
55 e.message.should =~ /Missing setting 'missing' in/
04fddca real-world bugfixes from Vlad and sub-key errors
Nate Wiger authored
56
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
57 e = nil
58 begin
59 Settings.language.missing
60 rescue => e
61 e.should be_kind_of Settingslogic::MissingSetting
62 end
63 e.should_not be_nil
64 e.message.should =~ /Missing setting 'missing' in 'language' section/
65 end
66
67 it "should handle optional / dynamic settings" do
68 e = nil
69 begin
70 Settings.language.erlang
71 rescue => e
72 e.should be_kind_of Settingslogic::MissingSetting
73 end
74 e.should_not be_nil
75 e.message.should =~ /Missing setting 'erlang' in 'language' section/
76
77 Settings.language['erlang'].should be_nil
04fddca real-world bugfixes from Vlad and sub-key errors
Nate Wiger authored
78 Settings.language['erlang'] = 5
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
79 Settings.language['erlang'].should == 5
80
81 Settings.language['erlang'] = {'paradigm' => 'functional'}
82 Settings.language.erlang.paradigm.should == 'functional'
77825ec solved Vlad collision finally by proxying top-level accessor to instance
Nate Wiger authored
83 Settings.respond_to?('erlang').should be_false
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
84
85 Settings.reload!
86 Settings.language['erlang'].should be_nil
04fddca real-world bugfixes from Vlad and sub-key errors
Nate Wiger authored
87
88 Settings.language[:erlang] ||= 5
89 Settings.language[:erlang].should == 5
90
91 Settings.language[:erlang] = {}
92 Settings.language[:erlang][:paradigm] = 'functional'
93 Settings.language.erlang.paradigm.should == 'functional'
872a103 slight reorg and added spec demonstrating remaining edge case
Nate Wiger authored
94
95 Settings[:toplevel] = '42'
96 Settings.toplevel.should == '42'
04fddca real-world bugfixes from Vlad and sub-key errors
Nate Wiger authored
97 end
98
eeadde3 handling of nil (missing) file specified as source
Nate Wiger authored
99 it "should raise an error on a nil source argument" do
100 class NoSource < Settingslogic; end
101 e = nil
102 begin
103 NoSource.foo.bar
104 rescue => e
105 e.should be_kind_of Errno::ENOENT
106 end
107 e.should_not be_nil
108 end
109
872a103 slight reorg and added spec demonstrating remaining edge case
Nate Wiger authored
110 # This one edge case currently does not pass, because it requires very
111 # esoteric code in order to make it pass. It was judged not worth fixing,
112 # as it introduces significant complexity for minor gain.
113 # it "should handle reloading top-level settings"
114 # Settings[:inspect] = 'yeah baby'
115 # Settings.inspect.should == 'yeah baby'
116 # Settings.reload!
117 # Settings.inspect.should == 'Settings'
118 # end
119
805df68 more tests; have pinpointed collisions to top-level settings only
Nate Wiger authored
120 it "should handle oddly-named settings" do
04fddca real-world bugfixes from Vlad and sub-key errors
Nate Wiger authored
121 Settings.language['some-dash-setting#'] = 'dashtastic'
122 Settings.language['some-dash-setting#'].should == 'dashtastic'
123 end
124
805df68 more tests; have pinpointed collisions to top-level settings only
Nate Wiger authored
125 it "should support instance usage as well" do
126 settings = SettingsInst.new(Settings.source)
127 settings.setting1.setting1_child.should == "saweet"
128 end
129
04fddca real-world bugfixes from Vlad and sub-key errors
Nate Wiger authored
130 it "should be able to get() a key with dot.notation" do
131 Settings.get('setting1.setting1_child').should == "saweet"
132 Settings.get('setting1.deep.another').should == "my value"
133 Settings.get('setting1.deep.child.value').should == 2
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
134 end
135
975252e @goosetav fixes settingslogic #11
goosetav authored
136 # If .name is not a property, delegate to superclass
137 it "should respond with Module.name" do
138 Settings2.name.should == "Settings2"
139 end
140
141 # If .name is called on Settingslogic itself, handle appropriately
142 # by delegating to Hash
143 it "should have the parent class always respond with Module.name" do
144 Settingslogic.name.should == 'Settingslogic'
145 end
146
147 # If .name is a property, respond with that instead of delegating to superclass
148 it "should allow a name setting to be overriden" do
149 Settings.name.should == 'test'
150 end
151
c8da048 def keys as methods rather than using method_missing, added load!/reload...
Nate Wiger authored
152 # Put this test last or else call to .instance will load @instance,
153 # masking bugs.
154 it "should be a hash" do
155 Settings.send(:instance).should be_is_a(Hash)
156 end
975252e @goosetav fixes settingslogic #11
goosetav authored
157
28dc69b @MitinPavel The issue with 'nested keys' was fixed.
MitinPavel authored
158 end
Something went wrong with that request. Please try again.