configurate 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1c77311fcc9be9b8545a349cb8a9352fac266ba
4
+ data.tar.gz: 23cc86a4bc3e0edad45c756eb77a27a97628cb3c
5
+ SHA512:
6
+ metadata.gz: 0f9b04ce701034847ce8d337093a692bae175e75c8b68b30de0260bfe20520350f6d0112a0423df972d564321b23b4a91a35160d1186899fef1c3d2f61f64388
7
+ data.tar.gz: f48dbe835f2cb4b2102d8090a1b030612b19f52a7b2b23d517eb6cbc7bc748304a6cac4a1a6826eb90367ad77e73e783735b7bb9be02901766c8a5ea1680bf43
@@ -0,0 +1,11 @@
1
+ -----BEGIN PGP SIGNATURE-----
2
+ Version: GnuPG v2
3
+
4
+ iQEcBAABAgAGBQJUJcgAAAoJEPNH4OtHrHDWwu0IAIPCkoGVvTACKyK1T3wq/1MY
5
+ /Ea17MjRfBzNZ4vagFJd8LZAIf58ZFGYPiFhvZim26o7WVIf6BGUNDQUDC+CKAg6
6
+ iFXfbPjXXjuB3v1mylZ81ZWcfkyClda2T95LHdsdJ52s/ciar2L1QvngM/MR1+Vr
7
+ 5nmnBS9OFA3/OsQVJKWi1oKClfz4RLFCcI16Y3gyH9WrsLFlCr2McJ/lTr6U/D8x
8
+ XLrUEcMMYWK7G7qc0C9WKD7+Y/lVLpjZSWElC+Mm9dGpK0Q5K01RbU2zd8O15uDM
9
+ ycwtvFvOnwdKjTRUx/m+LH5ey42nawOgtFhbmDmdwfJwo0gUTtqVvltNGnqgxKo=
10
+ =ryWj
11
+ -----END PGP SIGNATURE-----
data.tar.gz.asc CHANGED
@@ -1,11 +1,11 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG v2.0.20 (GNU/Linux)
2
+ Version: GnuPG v2
3
3
 
4
- iQEcBAABAgAGBQJRrlMbAAoJEPNH4OtHrHDWnC0H/RMF7kn/MJ6sDIugAmWQXK43
5
- BGyu3+oXLhDPkTOh090/xhajnDh2FqOFVgzdpJRTLkzffC5boy6gOw4c0FeOZJob
6
- Vm0SiaBBv6qY9PNhUjjcvIH611oaAU/5WLqydCKPl49WKmhd4LGoH/iTnKWeVJWs
7
- QPrYytfL7YDb8r0zAM/iQ39QI0Wtm+abPSY4zlBv5ZgkyRpbchYC7h7oetJYG9A1
8
- C8MmoKBA2+aIrWomCcPWTcpuDTFV41Kyrrts7y/4KVc/bpnZo6t56mWmiFDtiMOi
9
- WQ13Z49/2yMeLIQs5GW98ZS8r2EdkcW+ZzIJQuL7nPGmRqlRFgzs212qc/0gx/Y=
10
- =+Q/C
4
+ iQEcBAABAgAGBQJUJcgAAAoJEPNH4OtHrHDW6fEH/1cAw0GslySQkuKPc2SvjC5r
5
+ hc3rYNdp7P7RA+a4liD9d/qRjCYWvkV1/dg57B2/PouXT/e/D9+cCvRpgtu1E3lv
6
+ Oecgh+mV/jR7mxfwr4xdLjGX0JajP/VnI/IEcxjLi7ht3tYkztdRACNhIzfjCqdc
7
+ cGyV3dAbmt3bflf85YbDAUcQkkwnFOLCZQUfepgxjgv1/BBBEKXp68+5wge2q2co
8
+ +yTmV6LXU+2B8hwDwJpjB1V6lxJKh61gwK3zNexqsYLGn5C7SjxSBdObvs2wCAAR
9
+ 9XdG9pkpavHEiYBBXQe5zjDUIWRGIP+Y2/tfVTr74sQ76k7Q4bDSAovoVUwhVQs=
10
+ =4Tkj
11
11
  -----END PGP SIGNATURE-----
@@ -0,0 +1,45 @@
1
+ # 0.1.0
2
+
3
+ * Dynamic provider resolves nested assignments
4
+
5
+ # 0.0.8
6
+
7
+ * Include README.md into the gem
8
+ * Skip namespace warning if there but empty
9
+ * Do not overwrite dup in SettingPath
10
+ * Fix tolerant loading of coveralls in the spec helper
11
+ * Improve comparisions in Proxy
12
+
13
+ # 0.0.7
14
+
15
+ * Only directly delegate methods returning meta-information in SettingPath
16
+ * Clean output of more methods in SettingPath
17
+ * Sanitize more input methods in SettingPath
18
+
19
+ # 0.0.6
20
+
21
+ * Use Forwardable instead of method_missing where possible
22
+ * Fix warning message on invalid namespace in YAML provider
23
+ * Refactor SettingPath to correctly handle special paths in way more places
24
+ * SettingPath#new now handles string paths, dropped SettingPath::from_string
25
+
26
+ # 0.0.4/0.0.5
27
+
28
+ * Pass duplicates of SettingPath into the provider so that it can be modified by it.
29
+ * Ensure SettingPath elements are strings
30
+
31
+ # 0.0.3
32
+
33
+ * Support Ruby 2.0.0
34
+ * Prefer `public_send` over `send`
35
+ * Manage setting paths through dedicated objects
36
+ * Pass new SettingPath objects directly into the providers
37
+ * Improve specs
38
+
39
+ # 0.0.2
40
+
41
+ * Return duplicates from the environment provider so that the return value can be modified by the client.
42
+
43
+ # 0.0.1
44
+
45
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Jonne Haß
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Configurate - A flexible configuration system
2
2
  [![Gem Version](https://badge.fury.io/rb/configurate.png)](https://rubygems.org/gems/configurate)
3
- [![Build Status](https://secure.travis-ci.org/MrZYX/configurate.png?branch=master)](https://travis-ci.org/MrZYX/configurate)
3
+ [![Build Status](https://secure.travis-ci.org/jhass/configurate.png?branch=master)](https://travis-ci.org/jhass/configurate)
4
4
  [![Gemnasium](https://gemnasium.com/MrZYX/configurate.png)](https://gemnasium.com/MrZYX/configurate)
5
- [![Code Climate](https://codeclimate.com/github/MrZYX/configurate.png)](https://codeclimate.com/github/MrZYX/configurate)
6
- [![Coverage Status](https://coveralls.io/repos/MrZYX/configurate/badge.png?branch=master)](https://coveralls.io/r/MrZYX/configurate)
5
+ [![Code Climate](https://codeclimate.com/github/jhass/configurate.png)](https://codeclimate.com/github/MrZYX/configurate)
6
+ [![Coverage Status](https://coveralls.io/repos/jhass/configurate/badge.png?branch=master)](https://coveralls.io/r/MrZYX/configurate)
7
7
 
8
8
  Configurate allows you to specify a chain of configuration providers which are
9
9
  queried in order until one returns a value. This allows scenarios like overriding
@@ -186,7 +186,7 @@ end
186
186
 
187
187
  ## Documentation
188
188
 
189
- You can find the current documentation for the master branch [here](http://rubydoc.info/github/MrZYX/configurate/master/frames/index).
189
+ You can find the current documentation for the master branch [here](http://rubydoc.info/github/jhass/configurate/master/frames/index).
190
190
 
191
191
 
192
192
  ## License
@@ -11,6 +11,20 @@ module Configurate; module Provider
11
11
  raise Configurate::SettingNotFoundError, "The setting #{args.first} was not found"
12
12
  end
13
13
  end
14
+
15
+ # Utility function to lookup a settings path in a hash
16
+ # @param setting_path [SettingPath]
17
+ # @param hash [Hash]
18
+ # @yield fallback value if not found
19
+ # @return [Object]
20
+ def self.lookup_in_hash setting_path, hash, &fallback
21
+ fallback ||= proc { nil }
22
+ while hash.is_a?(Hash) && hash.has_key?(setting_path.first) && !setting_path.empty?
23
+ hash = hash[setting_path.shift]
24
+ end
25
+ return fallback.call unless setting_path.empty?
26
+ hash
27
+ end
14
28
  end; end
15
29
 
16
30
  require 'configurate/provider/yaml'
@@ -7,17 +7,17 @@ module Configurate; module Provider
7
7
  def initialize
8
8
  @settings = {}
9
9
  end
10
-
11
- def lookup_path(setting_path, *args)
12
- key = setting_path.to_s
13
-
10
+
11
+ def lookup_path(setting_path, *args)
14
12
  if setting_path.is_setter? && args.length > 0
15
13
  value = args.first
16
14
  value = value.get if value.respond_to?(:_proxy?) && value._proxy?
17
- @settings[key] = value
15
+ *root, key = setting_path.to_a
16
+ hash = root.inject(@settings) {|hash, key| hash[key] ||= {} }
17
+ hash[key] = value
18
18
  end
19
-
20
- @settings[key]
19
+
20
+ Provider.lookup_in_hash setting_path, @settings
21
21
  end
22
22
  end
23
23
  end; end
@@ -11,38 +11,27 @@ module Configurate; module Provider
11
11
  # the file or the namespace, if given, is not found. Defaults to +true+.
12
12
  # @raise [ArgumentError] if the namespace isn't found in the file
13
13
  # @raise [Errno:ENOENT] if the file isn't found
14
- def initialize(file, opts = {})
14
+ def initialize file, opts = {}
15
15
  @settings = {}
16
16
  required = opts.delete(:required) { true }
17
-
17
+
18
18
  @settings = ::YAML.load_file(file)
19
-
19
+
20
20
  namespace = opts.delete(:namespace)
21
21
  unless namespace.nil?
22
- @settings = lookup_in_hash(SettingPath.new(namespace), @settings) do
22
+ @settings = Provider.lookup_in_hash(SettingPath.new(namespace), @settings) do
23
23
  raise ArgumentError, "Namespace #{namespace} not found in #{file}" if required
24
24
  $stderr.puts "WARNING: Namespace #{namespace} not found in #{file}"
25
+ nil
25
26
  end
26
27
  end
27
28
  rescue Errno::ENOENT => e
28
29
  $stderr.puts "WARNING: Configuration file #{file} not found, ensure it's present"
29
30
  raise e if required
30
31
  end
31
-
32
-
33
- def lookup_path(setting_path, *)
34
- lookup_in_hash(setting_path, @settings)
35
- end
36
-
37
- private
38
-
39
- def lookup_in_hash(setting_path, hash, &fallback)
40
- fallback ||= proc { nil }
41
- while hash.is_a?(Hash) && hash.has_key?(setting_path.first) && !setting_path.empty?
42
- hash = hash[setting_path.shift]
43
- end
44
- return fallback.call unless setting_path.empty?
45
- hash
32
+
33
+ def lookup_path setting_path, *_
34
+ Provider.lookup_in_hash(setting_path, @settings)
46
35
  end
47
36
  end
48
37
  end; end
@@ -7,98 +7,98 @@ end
7
7
 
8
8
  describe Configurate::LookupChain do
9
9
  subject { described_class.new }
10
-
10
+
11
11
  describe "#add_provider" do
12
12
  it "adds a valid provider" do
13
13
  expect {
14
14
  subject.add_provider ValidConfigurationProvider
15
15
  }.to change { subject.instance_variable_get(:@provider).size }.by 1
16
16
  end
17
-
17
+
18
18
  it "doesn't add an invalid provider" do
19
19
  expect {
20
20
  subject.add_provider InvalidConfigurationProvider
21
21
  }.to raise_error ArgumentError
22
22
  end
23
-
23
+
24
24
  it "passes extra args to the provider" do
25
- ValidConfigurationProvider.should_receive(:new).with(:extra)
25
+ expect(ValidConfigurationProvider).to receive(:new).with(:extra)
26
26
  subject.add_provider ValidConfigurationProvider, :extra
27
27
  end
28
28
  end
29
-
29
+
30
30
  describe "#lookup" do
31
31
  before do
32
32
  subject.add_provider ValidConfigurationProvider
33
33
  subject.add_provider ValidConfigurationProvider
34
34
  @provider = subject.instance_variable_get(:@provider)
35
35
  end
36
-
36
+
37
37
  it "it tries all providers" do
38
38
  setting = Configurate::SettingPath.new "some.setting"
39
- setting.stub(:clone).and_return(setting)
39
+ allow(setting).to receive(:clone).and_return(setting)
40
40
  @provider.each do |provider|
41
- provider.should_receive(:lookup).with(setting).and_raise(Configurate::SettingNotFoundError)
41
+ expect(provider).to receive(:lookup).with(setting).and_raise(Configurate::SettingNotFoundError)
42
42
  end
43
-
43
+
44
44
  subject.lookup(setting)
45
45
  end
46
46
 
47
47
  it "converts a string to a SettingPath" do
48
48
  provider = @provider.first
49
- path = stub
50
- path.stub(:clone).and_return(path)
51
- provider.should_receive(:lookup).with(path).and_raise(Configurate::SettingNotFoundError)
49
+ path = double
50
+ allow(path).to receive(:clone).and_return(path)
51
+ expect(provider).to receive(:lookup).with(path).and_raise(Configurate::SettingNotFoundError)
52
52
  setting = "bar"
53
- Configurate::SettingPath.should_receive(:new).with(setting).and_return(path)
53
+ expect(Configurate::SettingPath).to receive(:new).with(setting).and_return(path)
54
54
  subject.lookup(setting)
55
55
  end
56
56
 
57
57
  it "passes a copy of the SettingPath to the provider" do
58
58
  provider = @provider.first
59
- path = mock("path")
60
- copy = stub("copy")
61
- path.should_receive(:clone).at_least(:once).and_return(copy)
62
- provider.should_receive(:lookup).with(copy).and_raise(Configurate::SettingNotFoundError)
59
+ path = double("path")
60
+ copy = double("copy")
61
+ expect(path).to receive(:clone).at_least(:once).and_return(copy)
62
+ expect(provider).to receive(:lookup).with(copy).and_raise(Configurate::SettingNotFoundError)
63
63
  subject.lookup(path)
64
64
  end
65
-
65
+
66
66
  it "stops if a value is found" do
67
- @provider[0].should_receive(:lookup).and_return("something")
68
- @provider[1].should_not_receive(:lookup)
67
+ expect(@provider[0]).to receive(:lookup).and_return("something")
68
+ expect(@provider[1]).to_not receive(:lookup)
69
69
  subject.lookup("bla")
70
70
  end
71
-
71
+
72
72
  it "converts numbers to strings" do
73
- @provider[0].stub(:lookup).and_return(5)
74
- subject.lookup("foo").should == "5"
73
+ allow(@provider[0]).to receive(:lookup).and_return(5)
74
+ expect(subject.lookup "foo").to eq "5"
75
75
  end
76
-
76
+
77
77
  it "does not convert false to a string" do
78
- @provider[0].stub(:lookup).and_return(false)
79
- subject.lookup("enable").should be_false
78
+ allow(@provider[0]).to receive(:lookup).and_return(false)
79
+ expect(subject.lookup "enable").to be_falsey
80
80
  end
81
81
 
82
82
  it "converts 'true' to true" do
83
- @provider[0].stub(:lookup).and_return("true")
84
- subject.lookup("enable").should be_true
83
+ allow(@provider[0]).to receive(:lookup).and_return("true")
84
+ expect(subject.lookup "enable").to be_truthy
85
85
  end
86
86
 
87
87
  it "converts 'false' to false" do
88
- @provider[0].stub(:lookup).and_return("false")
89
- subject.lookup("enable").should be_false
88
+ allow(@provider[0]).to receive(:lookup).and_return("false")
89
+ expect(subject.lookup "enable").to be_falsey
90
90
  end
91
91
 
92
92
  it "returns the value unchanged if it can't be converted" do
93
- value = mock
94
- value.stub(:respond_to?).with(:to_s).and_return(false)
95
- @provider[0].stub(:lookup).and_return(value)
96
- subject.lookup("enable").should == value
93
+ value = double
94
+ allow(value).to receive(:respond_to?).with(:to_s).and_return(false)
95
+ allow(@provider[0]).to receive(:lookup).and_return(value)
96
+ expect(subject.lookup "enable").to eq value
97
97
  end
98
-
98
+
99
99
  it "returns nil if no value is found" do
100
- @provider.each { |p| p.stub(:lookup).and_raise(Configurate::SettingNotFoundError) }
101
- subject.lookup("not.me").should be_nil
100
+ @provider.each { |p| allow(p).to receive(:lookup).and_raise(Configurate::SettingNotFoundError) }
101
+ expect(subject.lookup "not.me").to be_nil
102
102
  end
103
103
  end
104
104
  end
@@ -4,20 +4,24 @@ describe Configurate::Provider::Dynamic do
4
4
  subject { described_class.new }
5
5
  describe "#lookup_path" do
6
6
  it "returns nil if the setting was never set" do
7
- subject.lookup_path(Configurate::SettingPath.new(["not_me"])).should be_nil
7
+ expect(subject.lookup_path Configurate::SettingPath.new(["not_me"]) ).to be_nil
8
8
  end
9
-
9
+
10
10
  it "remembers the setting if it ends with =" do
11
- subject.lookup_path(Configurate::SettingPath.new(["find_me", "later="]), "there")
12
- subject.lookup_path(Configurate::SettingPath.new(["find_me", "later"])).should == "there"
11
+ subject.lookup_path Configurate::SettingPath.new(["find_me", "later="]), "there"
12
+
13
+ expect(subject.lookup_path Configurate::SettingPath.new(["find_me", "later"]) ).to eq "there"
13
14
  end
14
-
15
+
15
16
  it "calls .get on the argument if a proxy object is given" do
16
- proxy = mock
17
- proxy.stub(:respond_to?).and_return(true)
18
- proxy.stub(:_proxy?).and_return(true)
19
- proxy.should_receive(:get)
20
- subject.lookup_path(Configurate::SettingPath.new(["bla="]), proxy)
17
+ proxy = double(respond_to: true, _proxy?: true)
18
+ expect(proxy).to receive(:get)
19
+ subject.lookup_path Configurate::SettingPath.new(["bla="]), proxy
20
+ end
21
+
22
+ it "resolves nested calls after group assignment" do
23
+ subject.lookup_path Configurate::SettingPath.new(["find_me", "later="]), {"a" => "b"}
24
+ expect(subject.lookup_path Configurate::SettingPath.new(["find_me", "later", "a"])).to eq "b"
21
25
  end
22
26
  end
23
27
  end
@@ -9,26 +9,26 @@ describe Configurate::Provider::Env do
9
9
  ENV['EXISTING_SETTING'] = "there"
10
10
  ENV['ARRAY'] = "foo,bar,baz"
11
11
  end
12
-
12
+
13
13
  after(:all) do
14
14
  ENV['EXISTING_SETTING'] = nil
15
15
  ENV['ARRAY'] = nil
16
16
  end
17
-
17
+
18
18
  describe '#lookup_path' do
19
19
  it "joins and upcases the path" do
20
- ENV.should_receive(:[]).with("EXISTING_SETTING")
21
- subject.lookup_path(existing_path)
20
+ expect(ENV).to receive(:[]).with("EXISTING_SETTING")
21
+ subject.lookup_path existing_path
22
22
  end
23
-
23
+
24
24
  it "returns nil if the setting isn't available" do
25
- subject.lookup_path(not_existing_path).should be_nil
25
+ expect(subject.lookup_path not_existing_path).to be_nil
26
26
  end
27
-
27
+
28
28
  it "makes an array out of comma separated values" do
29
- subject.lookup_path(array_path).should == ["foo", "bar", "baz"]
29
+ expect(subject.lookup_path array_path).to eq ["foo", "bar", "baz"]
30
30
  end
31
-
31
+
32
32
  it "returns a unfrozen string" do
33
33
  expect {
34
34
  setting = subject.lookup_path(existing_path)
@@ -2,80 +2,80 @@ require 'spec_helper'
2
2
 
3
3
  describe Configurate::Provider::YAML do
4
4
  let(:settings) { {"toplevel" => "bar",
5
- "some" => {
5
+ "some" => {
6
6
  "nested" => { "some" => "lala", "setting" => "foo"}
7
7
  }
8
8
  } }
9
-
9
+
10
10
  describe "#initialize" do
11
11
  it "loads the file" do
12
12
  file = "foobar.yml"
13
- ::YAML.should_receive(:load_file).with(file).and_return({})
13
+ expect(::YAML).to receive(:load_file).with(file).and_return({})
14
14
  described_class.new file
15
15
  end
16
-
16
+
17
17
  it "raises if the file is not found" do
18
- ::YAML.stub(:load_file).and_raise(Errno::ENOENT)
18
+ allow(::YAML).to receive(:load_file).and_raise(Errno::ENOENT)
19
19
  expect {
20
20
  silence_stderr do
21
21
  described_class.new "foo"
22
22
  end
23
23
  }.to raise_error Errno::ENOENT
24
24
  end
25
-
26
-
25
+
26
+
27
27
  context "with a namespace" do
28
28
  it "looks in the file for that namespace" do
29
29
  namespace = "some.nested"
30
- ::YAML.stub(:load_file).and_return(settings)
30
+ allow(::YAML).to receive(:load_file).and_return(settings)
31
31
  provider = described_class.new 'bla', namespace: namespace
32
- provider.instance_variable_get(:@settings).should == settings['some']['nested']
32
+ expect(provider.instance_variable_get :@settings).to eq settings['some']['nested']
33
33
  end
34
-
34
+
35
35
  it "raises if the namespace isn't found" do
36
- ::YAML.stub(:load_file).and_return({})
36
+ allow(::YAML).to receive(:load_file).and_return({})
37
37
  expect {
38
38
  described_class.new 'bla', namespace: "bar"
39
- }.to raise_error ArgumentError
39
+ }.to raise_error
40
40
  end
41
41
 
42
42
  it "works with an empty namespace in the file" do
43
- ::YAML.stub(:load_file).and_return({'foo' => {'bar' => nil}})
43
+ allow(::YAML).to receive(:load_file).and_return({'foo' => {'bar' => nil}})
44
44
  expect {
45
45
  described_class.new 'bla', namespace: "foo.bar"
46
- }.to_not raise_error ArgumentError
46
+ }.to_not raise_error
47
47
  end
48
48
  end
49
-
49
+
50
50
  context "with required set to false" do
51
51
  it "doesn't raise if a file isn't found" do
52
- ::YAML.stub(:load_file).and_raise(Errno::ENOENT)
52
+ allow(::YAML).to receive(:load_file).and_raise(Errno::ENOENT)
53
53
  expect {
54
54
  described_class.new "not_me", required: false
55
- }.not_to raise_error Errno::ENOENT
55
+ }.not_to raise_error
56
56
  end
57
-
57
+
58
58
  it "doesn't raise if a namespace isn't found" do
59
- ::YAML.stub(:load_file).and_return({})
59
+ allow(::YAML).to receive(:load_file).and_return({})
60
60
  expect {
61
61
  described_class.new 'bla', namespace: "foo", required: false
62
- }.not_to raise_error ArgumentError
62
+ }.not_to raise_error
63
63
  end
64
64
  end
65
65
  end
66
-
66
+
67
67
  describe "#lookup_path" do
68
68
  before do
69
- ::YAML.stub(:load_file).and_return(settings)
69
+ allow(::YAML).to receive(:load_file).and_return(settings)
70
70
  @provider = described_class.new 'dummy'
71
71
  end
72
-
72
+
73
73
  it "looks up the whole nesting" do
74
- @provider.lookup_path(["some", "nested", "some"]).should == settings["some"]["nested"]["some"]
74
+ expect(@provider.lookup_path ["some", "nested", "some"]).to eq settings["some"]["nested"]["some"]
75
75
  end
76
-
76
+
77
77
  it "returns nil if no setting is found" do
78
- @provider.lookup_path(["not_me"]).should be_nil
78
+ expect(@provider.lookup_path ["not_me"]).to be_nil
79
79
  end
80
80
  end
81
81
  end
@@ -5,12 +5,12 @@ describe Configurate::Provider::Base do
5
5
  subject { described_class.new }
6
6
  it "calls #lookup_path" do
7
7
  path = Configurate::SettingPath.new(["foo", "bar"])
8
- subject.should_receive(:lookup_path).with(path).and_return("something")
9
- subject.lookup(path).should == "something"
8
+ expect(subject).to receive(:lookup_path).with(path).and_return("something")
9
+ expect(subject.lookup(path)).to eq "something"
10
10
  end
11
-
11
+
12
12
  it "raises SettingNotFoundError if the #lookup_path returns nil" do
13
- subject.stub(:lookup_path).and_return(nil)
13
+ allow(subject).to receive(:lookup_path).and_return(nil)
14
14
  expect {
15
15
  subject.lookup("bla")
16
16
  }.to raise_error Configurate::SettingNotFoundError
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Configurate::Proxy do
4
- let(:lookup_chain) { mock(lookup: "something") }
4
+ let(:lookup_chain) { double(lookup: "something") }
5
5
  let(:proxy) { described_class.new(lookup_chain) }
6
6
 
7
7
  describe "in case statements" do
@@ -13,66 +13,64 @@ describe Configurate::Proxy do
13
13
  else
14
14
  "wrong"
15
15
  end
16
- result.should == "string"
16
+ expect(result).to eq "string"
17
17
  end
18
18
  end
19
-
19
+
20
20
  describe "#method_missing" do
21
21
  it "calls #target if the method ends with a ?" do
22
- lookup_chain.should_receive(:lookup).and_return(false)
22
+ expect(lookup_chain).to receive(:lookup).and_return(false)
23
23
  proxy.method_missing(:enable?)
24
24
  end
25
-
25
+
26
26
  it "calls #target if the method ends with a =" do
27
- lookup_chain.should_receive(:lookup).and_return(false)
27
+ expect(lookup_chain).to receive(:lookup).and_return(false)
28
28
  proxy.method_missing(:url=)
29
29
  end
30
30
  end
31
31
 
32
32
  describe "delegations" do
33
33
  it "calls the target when negating" do
34
- target = mock
35
- lookup_chain.stub(:lookup).and_return(target)
36
- target.should_receive(:!)
34
+ target = double
35
+ allow(lookup_chain).to receive(:lookup).and_return(target)
36
+ expect(target).to receive(:!)
37
37
  proxy.something.__send__(:!)
38
38
  end
39
39
 
40
40
  it "enables sends even though be BasicObject" do
41
- proxy.should_receive(:foo)
41
+ expect(proxy).to receive(:foo)
42
42
  proxy.send(:foo)
43
43
  end
44
44
  end
45
45
 
46
46
  describe "#proxy" do
47
47
  subject { proxy._proxy? }
48
- it { should be_true }
48
+ it { should be_truthy }
49
49
  end
50
-
50
+
51
51
  describe "#target" do
52
52
  [:to_str, :to_s, :to_xml, :respond_to?, :present?, :!=, :eql?,
53
53
  :each, :try, :size, :length, :count, :==, :=~, :gsub, :blank?, :chop,
54
54
  :start_with?, :end_with?].each do |method|
55
55
  it "is called for accessing #{method} on the proxy" do
56
- target = mock
57
- lookup_chain.stub(:lookup).and_return(target)
58
- target.stub(:respond_to?).and_return(true)
59
- target.stub(:_proxy?).and_return(false)
60
- target.should_receive(method).and_return("something")
61
- proxy.something.__send__(method, mock)
56
+ target = double(respond_to?: true, _proxy?: false)
57
+ allow(lookup_chain).to receive(:lookup).and_return(target)
58
+ expect(target).to receive(method).and_return("something")
59
+ proxy.something.__send__(method, double)
62
60
  end
63
61
  end
64
-
62
+
65
63
  described_class::COMMON_KEY_NAMES.each do |method|
66
64
  it "is not called for accessing #{method} on the proxy" do
67
- target = mock
68
- lookup_chain.should_not_receive(:lookup)
69
- target.should_not_receive(method)
70
- proxy.something.__send__(method, mock)
65
+ target = double
66
+ expect(lookup_chain).to_not receive(:lookup)
67
+ expect(target).to_not receive(method)
68
+ proxy.something.__send__(method, double)
71
69
  end
72
70
  end
73
-
71
+
74
72
  it "returns nil if no setting is given" do
75
- proxy.target.should be_nil
73
+ expect(proxy.target).to be_nil
76
74
  end
77
75
  end
78
76
  end
@@ -9,7 +9,7 @@ describe Configurate::SettingPath do
9
9
  describe "#initialize" do
10
10
  context "with a string" do
11
11
  it "creates a path" do
12
- described_class.new(long_path.to_s).should == long_path
12
+ expect(described_class.new long_path.to_s).to eq long_path
13
13
  end
14
14
  end
15
15
  end
@@ -17,24 +17,24 @@ describe Configurate::SettingPath do
17
17
  describe "#is_question?" do
18
18
  context "with a question signature as setting" do
19
19
  subject { question_path.is_question? }
20
- it { should be_true }
20
+ it { should be_truthy }
21
21
  end
22
22
 
23
23
  context "with a normal path as setting" do
24
24
  subject { normal_path.is_question? }
25
- it { should be_false }
25
+ it { should be_falsey }
26
26
  end
27
27
  end
28
28
 
29
29
  describe "#is_setter?" do
30
30
  context "with a setter signature as setting" do
31
- subject { setter_path.is_setter? }
32
- it { should be_true }
31
+ subject { setter_path.is_setter? }
32
+ it { should be_truthy }
33
33
  end
34
34
 
35
35
  context "with a normal path as setting" do
36
36
  subject { normal_path.is_setter? }
37
- it { should be_false }
37
+ it { should be_falsey }
38
38
  end
39
39
  end
40
40
 
@@ -43,8 +43,8 @@ describe Configurate::SettingPath do
43
43
  original = described_class.new ["foo", "bar"]
44
44
  copy = original.clone
45
45
  copy << "baz"
46
- copy.should include "baz"
47
- original.should_not include "baz"
46
+ expect(copy).to include "baz"
47
+ expect(original).not_to include "baz"
48
48
  end
49
49
  end
50
50
 
@@ -52,23 +52,23 @@ describe Configurate::SettingPath do
52
52
  describe "#is_question_or_setter?" do
53
53
  context "with a question signature as setting" do
54
54
  subject { question_path.is_question_or_setter? }
55
- it { should be_true }
55
+ it { should be_truthy }
56
56
  end
57
57
 
58
58
  context "with a setter signature as setting" do
59
- subject { setter_path.is_question_or_setter? }
60
- it { should be_true }
59
+ subject { setter_path.is_question_or_setter? }
60
+ it { should be_truthy }
61
61
  end
62
62
 
63
63
  context "with a normal path as setting" do
64
64
  subject { normal_path.is_question_or_setter? }
65
- it { should be_false }
65
+ it { should be_falsey }
66
66
  end
67
67
  end
68
68
 
69
69
  describe "#each" do
70
70
  it "should strip special characters" do
71
- long_path.all? { |c| c.include? "?" }.should be_false
71
+ expect(long_path.all? { |c| c.include? "?" }).to be_falsey
72
72
  end
73
73
  end
74
74
 
@@ -82,8 +82,8 @@ describe Configurate::SettingPath do
82
82
  [:<<, :unshift, :push].each do |method|
83
83
  describe "##{method}" do
84
84
  it 'converts the argument to a string' do
85
- arg = mock
86
- arg.should_receive(:to_s).and_return('bar')
85
+ arg = double
86
+ expect(arg).to receive(:to_s).and_return('bar')
87
87
  described_class.new.public_send method, arg
88
88
  end
89
89
  end
@@ -103,7 +103,7 @@ describe Configurate::SettingPath do
103
103
  describe "#inspect" do
104
104
  it "includes the dotted path" do
105
105
  path = described_class.new([:foo, :bar])
106
- path.inspect.should include "foo.bar"
106
+ expect(path.inspect).to include "foo.bar"
107
107
  end
108
108
  end
109
109
  end
@@ -3,21 +3,21 @@ require 'spec_helper'
3
3
  describe Configurate::Settings do
4
4
  describe "#method_missing" do
5
5
  subject { described_class.create }
6
-
6
+
7
7
  it "delegates the call to a new proxy object" do
8
- proxy = mock
9
- Configurate::Proxy.should_receive(:new).and_return(proxy)
10
- proxy.should_receive(:method_missing).with(:some_setting).and_return("foo")
8
+ proxy = double
9
+ expect(Configurate::Proxy).to receive(:new).and_return(proxy)
10
+ expect(proxy).to receive(:method_missing).with(:some_setting).and_return("foo")
11
11
  subject.some_setting
12
12
  end
13
13
  end
14
-
14
+
15
15
  [:lookup, :add_provider, :[]].each do |method|
16
16
  describe "#{method}" do
17
17
  subject { described_class.create }
18
-
18
+
19
19
  it "delegates the call to #lookup_chain" do
20
- subject.lookup_chain.should_receive(method)
20
+ expect(subject.lookup_chain).to receive(method)
21
21
  subject.send(method)
22
22
  end
23
23
  end
@@ -20,7 +20,6 @@ def silence_stderr
20
20
  end
21
21
 
22
22
  RSpec.configure do |config|
23
- config.treat_symbols_as_metadata_keys_with_true_values = true
24
23
  config.run_all_when_everything_filtered = true
25
24
  config.filter_run :focus
26
25
 
@@ -29,4 +28,8 @@ RSpec.configure do |config|
29
28
  # the seed, which is printed after each run.
30
29
  # --seed 1234
31
30
  config.order = 'random'
31
+
32
+ config.expect_with :rspec do |expect_config|
33
+ expect_config.syntax = :expect
34
+ end
32
35
  end
metadata CHANGED
@@ -1,100 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configurate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jonne Haß
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-04 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 10.0.3
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 10.0.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: 2.12.0
33
+ version: '3.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
- version: 2.12.0
40
+ version: '3.0'
46
41
  description: Configurate is a flexible configuration system that can read settings
47
42
  from multiple sources at the same time.
48
- email: me@mrzyx.de
43
+ email: me@jhass.eu
49
44
  executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
48
+ - Changelog.md
49
+ - LICENSE
50
+ - README.md
51
+ - lib/configurate.rb
52
+ - lib/configurate/lookup_chain.rb
53
+ - lib/configurate/provider.rb
54
+ - lib/configurate/provider/dynamic.rb
53
55
  - lib/configurate/provider/env.rb
54
56
  - lib/configurate/provider/yaml.rb
55
- - lib/configurate/provider/dynamic.rb
56
57
  - lib/configurate/proxy.rb
57
- - lib/configurate/lookup_chain.rb
58
- - lib/configurate/provider.rb
59
58
  - lib/configurate/setting_path.rb
60
- - lib/configurate.rb
61
- - README.md
62
- - spec/configurate/provider_spec.rb
63
59
  - spec/configurate/lookup_chain_spec.rb
64
- - spec/configurate/provider/yaml_spec.rb
65
- - spec/configurate/provider/env_spec.rb
66
60
  - spec/configurate/provider/dynamic_spec.rb
67
- - spec/configurate/setting_path_spec.rb
61
+ - spec/configurate/provider/env_spec.rb
62
+ - spec/configurate/provider/yaml_spec.rb
63
+ - spec/configurate/provider_spec.rb
68
64
  - spec/configurate/proxy_spec.rb
69
- - spec/spec_helper.rb
65
+ - spec/configurate/setting_path_spec.rb
70
66
  - spec/configurate_spec.rb
71
- homepage: http://mrzyx.github.com/configurate
67
+ - spec/spec_helper.rb
68
+ homepage: http://jhass.github.io/configurate
72
69
  licenses:
73
70
  - MIT
71
+ metadata: {}
74
72
  post_install_message:
75
73
  rdoc_options: []
76
74
  require_paths:
77
75
  - lib
78
76
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
77
  requirements:
81
- - - ! '>='
78
+ - - ">="
82
79
  - !ruby/object:Gem::Version
83
80
  version: 1.9.2
84
81
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
82
  requirements:
87
- - - ! '>='
83
+ - - ">="
88
84
  - !ruby/object:Gem::Version
89
85
  version: '0'
90
- segments:
91
- - 0
92
- hash: 61337675234892431
93
86
  requirements: []
94
87
  rubyforge_project:
95
- rubygems_version: 1.8.25
88
+ rubygems_version: 2.4.1
96
89
  signing_key:
97
- specification_version: 3
90
+ specification_version: 4
98
91
  summary: Flexbile configuration system
99
92
  test_files:
100
93
  - spec/configurate/provider_spec.rb
metadata.gz.asc CHANGED
@@ -1,11 +1,11 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG v2.0.20 (GNU/Linux)
2
+ Version: GnuPG v2
3
3
 
4
- iQEcBAABAgAGBQJRrlMbAAoJEPNH4OtHrHDWzAQH/jluldbgxLrHmdrfNGxDOfuy
5
- frt0ZFgpUBkySAh6D16fJeDOu1ziPao8wHM+G4WpvC+szE0kgPoAQV68ON2x4zCL
6
- FkidnZ0sKHe1z3VKWtl181Du+qbkdz8AhAigTtZPWd2BqR7wniKgvR5j31d553SX
7
- bQI9ojwOwbOjREmQ795wn/xILE8jkh2tOu+GuMR6TTqY2xXOz3Ccjl+muCDPmnW2
8
- lQzwodaCVweEzR2AZrkK+MNI5Wq8Ox56RYh1DfHr7nk0jRDCnlSKBl0++EdV3Ies
9
- eZ2gJBtPGRWk/bumqjaz60QS7m9BwUnq+HqkIQzrxlX/IeVY8cjZG8wyDkWwgxg=
10
- =vOi8
4
+ iQEcBAABAgAGBQJUJcgAAAoJEPNH4OtHrHDWGi0H/1bZoFxs/WNJhIvM/NciG/lx
5
+ VNgn9R/R46sRZqjCU4EXUAicWAOggNhF78d6XAbdQJSE2aiokBxQrE/tci6q4iDU
6
+ I1LLbcahSmZle9fR2JsUpGtT7A8hyKYpCDUjUG7TY2Ktfas9qL1GEsDtPKVjmQNS
7
+ l0GTg1JQ7XZHSkRAdBWHn9geGnQBQ7AqAqREIK/6+zSAaN7QNtBijIg9h4EyBWXb
8
+ SDZILyvkgj6bt+eE+o32jrNleLMfJbGU9zlNl92l4O1bb5TspUKwq9JkpSR4ZRzd
9
+ jkt5H+gXfwF0/zltejfLlkp50fwF3XnWgy9cEAh/BNTVPzT0HgfJzq3YBPlM7Vo=
10
+ =QI26
11
11
  -----END PGP SIGNATURE-----