figleaf 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,5 +10,13 @@ module Figleaf
10
10
  end
11
11
  end
12
12
 
13
+ def to_hash
14
+ super.tap do |hash|
15
+ keys = hash.keys
16
+ keys.each do |key|
17
+ hash[key.to_sym] = hash.delete(key)
18
+ end
19
+ end
20
+ end
13
21
  end
14
22
  end
@@ -1,3 +1,3 @@
1
1
  module Figleaf
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1,7 +1,11 @@
1
1
  require 'spec_helper'
2
- require 'figleaf'
3
2
 
4
- describe Figleaf::Settings do
3
+ class FigleafConfigurationImplementer
4
+ include Figleaf::Configuration
5
+ end
6
+
7
+ describe Figleaf::Configuration do
8
+ let(:described_class) { FigleafConfigurationImplementer }
5
9
 
6
10
  describe "setters and getters" do
7
11
  context "auto define enabled" do
@@ -123,76 +127,4 @@ describe Figleaf::Settings do
123
127
  end
124
128
  end
125
129
 
126
- describe "self.load_settings" do
127
- let(:configuration) {
128
- {
129
- "test" => {
130
- "foo" => "bar",
131
- "bool_true" => true,
132
- "bool_false" => false
133
- }
134
- }
135
- }
136
-
137
- before do
138
- Dir.stub(:glob).and_return(["config/described_class/some_service.yml"])
139
- described_class.stub(:env).and_return("test")
140
- YAML.stub(:load_file).and_return(configuration)
141
-
142
- described_class.load_settings
143
- end
144
-
145
- it "should load some service" do
146
- described_class.some_service["foo"].should == "bar"
147
- end
148
-
149
- it "should load indifferently the key names" do
150
- described_class.some_service["foo"].should == "bar"
151
- described_class.some_service[:foo].should == "bar"
152
- end
153
-
154
- it "should create foo as a method" do
155
- described_class.some_service.foo.should == "bar"
156
- end
157
-
158
- it "should create bool_true? and return true" do
159
- described_class.some_service.bool_true?.should be_true
160
- end
161
-
162
- it "should create bool_false? and return false" do
163
- described_class.some_service.bool_false?.should be_false
164
- end
165
-
166
- it "should work for arrays as well" do
167
- YAML.stub(:load_file).and_return({ "test" => [1, 2] })
168
- described_class.load_settings
169
- described_class.some_service.should == [1, 2]
170
- end
171
-
172
- it "and for plain strings" do
173
- YAML.stub(:load_file).and_return({ "test" => "Hello, World!" })
174
- described_class.load_settings
175
- described_class.some_service.should == "Hello, World!"
176
- end
177
-
178
- it "and for booleans (true)" do
179
- YAML.stub(:load_file).and_return({ "test" => true })
180
- described_class.load_settings
181
- described_class.some_service.should be_true
182
- end
183
-
184
- it "and for booleans (false)" do
185
- YAML.stub(:load_file).and_return({ "test" => false })
186
- described_class.load_settings
187
- described_class.some_service.should be_false
188
- end
189
-
190
- it "should raise exception when loading an undefined value" do
191
- YAML.stub(:load_file).and_return({ "test" => {} })
192
- described_class.load_settings
193
- expect { described_class.some_service.blah }.to raise_error NoMethodError
194
- end
195
-
196
- end
197
-
198
130
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Figleaf::Fighash do
4
+ describe "#to_hash" do
5
+ it "should return class Hash" do
6
+ subject.to_hash.class.should == Hash
7
+ end
8
+
9
+ context "should have symbols as keys" do
10
+ it "for symbol keys" do
11
+ subject = described_class.new({ a: :b, c: 1, d: "foo" })
12
+ subject.to_hash.should == { a: :b, c: 1, d: "foo" }
13
+ end
14
+
15
+ it "for string keys" do
16
+ subject = described_class.new({ "a" => :b, "c" => 1, "d" => "foo" })
17
+ subject.to_hash.should == { a: :b, c: 1, d: "foo" }
18
+ end
19
+
20
+ it "should have symbols as keys inside two levels" do
21
+ subject = described_class.new({ a: { b: :d } })
22
+ subject.to_hash.should == { a: { b: :d } }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ class FigleafLoadSettingsImplementer
4
+ include Figleaf::Configuration
5
+ include Figleaf::LoadSettings
6
+ end
7
+
8
+ describe Figleaf::LoadSettings do
9
+ let(:described_class) { FigleafLoadSettingsImplementer }
10
+
11
+ describe "self.load_settings" do
12
+ let(:configuration) {
13
+ {
14
+ "test" => {
15
+ "foo" => "bar",
16
+ "bool_true" => true,
17
+ "bool_false" => false
18
+ }
19
+ }
20
+ }
21
+
22
+ before do
23
+ Dir.stub(:glob).and_return(["config/described_class/some_service.yml"])
24
+ described_class.stub(:env).and_return("test")
25
+ YAML.stub(:load_file).and_return(configuration)
26
+
27
+ described_class.load_settings
28
+ end
29
+
30
+ it "should load some service" do
31
+ described_class.some_service["foo"].should == "bar"
32
+ end
33
+
34
+ it "should load indifferently the key names" do
35
+ described_class.some_service["foo"].should == "bar"
36
+ described_class.some_service[:foo].should == "bar"
37
+ end
38
+
39
+ it "should create foo as a method" do
40
+ described_class.some_service.foo.should == "bar"
41
+ end
42
+
43
+ it "should create bool_true? and return true" do
44
+ described_class.some_service.bool_true?.should be_true
45
+ end
46
+
47
+ it "should create bool_false? and return false" do
48
+ described_class.some_service.bool_false?.should be_false
49
+ end
50
+
51
+ it "should work for arrays as well" do
52
+ YAML.stub(:load_file).and_return({ "test" => [1, 2] })
53
+ described_class.load_settings
54
+ described_class.some_service.should == [1, 2]
55
+ end
56
+
57
+ it "and for plain strings" do
58
+ YAML.stub(:load_file).and_return({ "test" => "Hello, World!" })
59
+ described_class.load_settings
60
+ described_class.some_service.should == "Hello, World!"
61
+ end
62
+
63
+ it "and for booleans (true)" do
64
+ YAML.stub(:load_file).and_return({ "test" => true })
65
+ described_class.load_settings
66
+ described_class.some_service.should be_true
67
+ end
68
+
69
+ it "and for booleans (false)" do
70
+ YAML.stub(:load_file).and_return({ "test" => false })
71
+ described_class.load_settings
72
+ described_class.some_service.should be_false
73
+ end
74
+
75
+ it "should raise exception when loading an undefined value" do
76
+ YAML.stub(:load_file).and_return({ "test" => {} })
77
+ described_class.load_settings
78
+ expect { described_class.some_service.blah }.to raise_error NoMethodError
79
+ end
80
+
81
+ end
82
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  require "rspec/core"
7
7
  require "rspec/mocks"
8
+ require "figleaf"
8
9
 
9
10
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
11
  RSpec.configure do |config|
@@ -16,5 +17,5 @@ RSpec.configure do |config|
16
17
  # order dependency and want to debug it, you can fix the order by providing
17
18
  # the seed, which is printed after each run.
18
19
  # --seed 1234
19
- config.order = 'random'
20
+ config.order = "random"
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figleaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -129,7 +129,9 @@ files:
129
129
  - lib/figleaf/load_settings.rb
130
130
  - lib/figleaf/settings.rb
131
131
  - lib/figleaf/version.rb
132
- - spec/settings_spec.rb
132
+ - spec/figleaf/configuration_spec.rb
133
+ - spec/figleaf/fighash_spec.rb
134
+ - spec/figleaf/load_settings_spec.rb
133
135
  - spec/spec_helper.rb
134
136
  homepage: http://github.com/challengepost/figleaf
135
137
  licenses: []
@@ -156,5 +158,7 @@ signing_key:
156
158
  specification_version: 3
157
159
  summary: YAML based DRY settings manager.
158
160
  test_files:
159
- - spec/settings_spec.rb
161
+ - spec/figleaf/configuration_spec.rb
162
+ - spec/figleaf/fighash_spec.rb
163
+ - spec/figleaf/load_settings_spec.rb
160
164
  - spec/spec_helper.rb