rsettings 0.5.0 → 0.6.0

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.
@@ -1,46 +1,46 @@
1
- require "spec_helper"
2
-
3
- describe BasicDiskSettings do
4
- let(:settings) {BasicDiskSettings.new}
5
-
6
- before do
7
- settings.clear
8
- end
9
-
10
- let(:a) { SettingName.new :a}
11
- let(:b) { SettingName.new :b}
12
-
13
- it "can store single setting" do
14
- settings.set :a => "value"
15
-
16
- expect(settings.get(a).to_s).to eql "value"
17
- end
18
-
19
- it "can store multiple settings at once" do
20
- settings.set :a => "value a", :b => "value b"
21
-
22
- expect(settings.get(a).to_s).to eql "value a"
23
- expect(settings.get(b).to_s).to eql "value b"
24
- end
25
-
26
- it "overwrites duplicates" do
27
- settings.set :a => "value a"
28
- settings.set :a => "another value for a"
29
-
30
- expect(settings.get(a).to_s).to eql "another value for a"
31
- end
32
-
33
- it "overwrites duplicates even when setting the same setting" do
34
- settings.set :a => "value a", :a => "another value for a"
35
-
36
- expect(settings.get(a).to_s).to eql "another value for a"
37
- end
38
-
39
- it "records all settings when you call set multiple times" do
40
- settings.set :a => "value a"
41
- settings.set :b => "value b"
42
-
43
- expect(settings.get(a).to_s).to_not be_nil
44
- expect(settings.get(b).to_s).to_not be_nil
45
- end
46
- end
1
+ require "spec_helper"
2
+
3
+ describe BasicDiskSettings do
4
+ let(:settings) {BasicDiskSettings.new}
5
+
6
+ before do
7
+ settings.clear
8
+ end
9
+
10
+ let(:a) { SettingName.new :a}
11
+ let(:b) { SettingName.new :b}
12
+
13
+ it "can store single setting" do
14
+ settings.set :a => "value"
15
+
16
+ expect(settings.get(a).to_s).to eql "value"
17
+ end
18
+
19
+ it "can store multiple settings at once" do
20
+ settings.set :a => "value a", :b => "value b"
21
+
22
+ expect(settings.get(a).to_s).to eql "value a"
23
+ expect(settings.get(b).to_s).to eql "value b"
24
+ end
25
+
26
+ it "overwrites duplicates" do
27
+ settings.set :a => "value a"
28
+ settings.set :a => "another value for a"
29
+
30
+ expect(settings.get(a).to_s).to eql "another value for a"
31
+ end
32
+
33
+ it "overwrites duplicates even when setting the same setting" do
34
+ settings.set :a => "value a", :a => "another value for a"
35
+
36
+ expect(settings.get(a).to_s).to eql "another value for a"
37
+ end
38
+
39
+ it "records all settings when you call set multiple times" do
40
+ settings.set :a => "value a"
41
+ settings.set :b => "value b"
42
+
43
+ expect(settings.get(a).to_s).to_not be_nil
44
+ expect(settings.get(b).to_s).to_not be_nil
45
+ end
46
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,2 @@
1
- require "rspec"
2
- require "rsettings"
1
+ require "rspec"
2
+ require "rsettings"
@@ -1,56 +1,56 @@
1
- require "spec_helper"
2
-
3
- describe "a settings fallback" do
4
- before do
5
- ENV.clear
6
-
7
- @disk_settings = BasicDiskSettings.new do
8
- clear
9
- set :jazzs_bike_shorts => "tight"
10
- end
11
- end
12
-
13
- let (:settings) do
14
- Settings.new do
15
- with_settings :chain => [EnvironmentSettings, BasicDiskSettings]
16
- end
17
- end
18
-
19
- let (:disk_settings) do
20
- @disk_settings
21
- end
22
-
23
- it "for example, you can fall back to a setting on disk" do
24
- expect(settings.jazzs_bike_shorts).to eql "tight"
25
- end
26
-
27
- it "you get the environment setting when it exists" do
28
- ENV["jazzs_bike_shorts"] = "this is from the environment variables"
29
-
30
- expect(settings.jazzs_bike_shorts).to eql "this is from the environment variables"
31
- end
32
-
33
- it "you can fallback one and not another" do
34
- ENV["b"] = "env b"
35
-
36
- disk_settings.clear
37
- disk_settings.set :a => "disk a", :b => "disk b"
38
-
39
- expect(settings.a).to eql "disk a"
40
- expect(settings.b).to eql "env b"
41
- end
42
-
43
- it "you can use ONLY disk if you like" do
44
- settings = Settings.new do
45
- with_settings BasicDiskSettings
46
- end
47
-
48
- ENV["ben_rules"] = "expect this to be ignored"
49
-
50
- disk_settings.clear
51
- disk_settings.on(:set){|e,args| puts args.first}
52
- disk_settings.set :ben_rules => "yes"
53
-
54
- expect(settings.ben_rules).to eql "yes"
55
- end
56
- end
1
+ require "spec_helper"
2
+
3
+ describe "a settings fallback" do
4
+ before do
5
+ ENV.clear
6
+
7
+ @disk_settings = BasicDiskSettings.new do
8
+ clear
9
+ set :jazzs_bike_shorts => "tight"
10
+ end
11
+ end
12
+
13
+ let (:settings) do
14
+ Settings.new do
15
+ with_settings :chain => [EnvironmentSettings, BasicDiskSettings]
16
+ end
17
+ end
18
+
19
+ let (:disk_settings) do
20
+ @disk_settings
21
+ end
22
+
23
+ it "for example, you can fall back to a setting on disk" do
24
+ expect(settings.jazzs_bike_shorts).to eql "tight"
25
+ end
26
+
27
+ it "you get the environment setting when it exists" do
28
+ ENV["jazzs_bike_shorts"] = "this is from the environment variables"
29
+
30
+ expect(settings.jazzs_bike_shorts).to eql "this is from the environment variables"
31
+ end
32
+
33
+ it "you can fallback one and not another" do
34
+ ENV["b"] = "env b"
35
+
36
+ disk_settings.clear
37
+ disk_settings.set :a => "disk a", :b => "disk b"
38
+
39
+ expect(settings.a).to eql "disk a"
40
+ expect(settings.b).to eql "env b"
41
+ end
42
+
43
+ it "you can use ONLY disk if you like" do
44
+ settings = Settings.new do
45
+ with_settings BasicDiskSettings
46
+ end
47
+
48
+ ENV["ben_rules"] = "expect this to be ignored"
49
+
50
+ disk_settings.clear
51
+ disk_settings.on(:set){|e,args| puts args.first}
52
+ disk_settings.set :ben_rules => "yes"
53
+
54
+ expect(settings.ben_rules).to eql "yes"
55
+ end
56
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Listing the current settings" do
4
+ it "tells me about defaults" do
5
+ settings = Settings.new do
6
+ default :color, :to => 'pink'
7
+ default :size, :to => 'L'
8
+ end
9
+
10
+ expect(settings.inspect).to match /<color> defaults to <pink>/
11
+ expect(settings.inspect).to match /<size> defaults to <L>/
12
+ end
13
+
14
+ it "tells me about mappings" do
15
+ settings = Settings.new do
16
+ let "C" => :color
17
+ end
18
+
19
+ expect(settings.inspect).to match /<color> is translated from <C>/
20
+ end
21
+ end
@@ -1,52 +1,52 @@
1
- require "spec_helper"
2
-
3
- describe "that you can translate storage names into whatever setting name you want" do
4
- it "can supply mappings" do
5
- settings = Settings.new do
6
- let "U" => :username
7
- let "P" => :password
8
- end
9
-
10
- ENV["U"] = "graeme.hay"
11
- ENV["P"] = "allblacks"
12
-
13
- expect(settings.username).to eql "graeme.hay"
14
- expect(settings.password).to eql "allblacks"
15
- end
16
-
17
- it "you can map some and not others" do
18
- settings_configured_with_username_mapping_only = Settings.new do
19
- let "U" => :username
20
- end
21
-
22
- ENV["U"] = "graeme.hay"
23
- ENV["P"] = "allblacks"
24
-
25
- expect(settings_configured_with_username_mapping_only.username).to eql "graeme.hay"
26
- expect(settings_configured_with_username_mapping_only.P).to eql "allblacks"
27
- end
28
-
29
- it "you can map none" do
30
- settings_configured_with_nothing = Settings.new do
31
-
32
- end
33
-
34
- ENV["U"] = "graeme.hay"
35
- ENV["P"] = "allblacks"
36
-
37
- expect(settings_configured_with_nothing.U).to eql "graeme.hay"
38
- expect(settings_configured_with_nothing.P).to eql "allblacks"
39
- end
40
-
41
- it "when the setting is not found it tells you the mapped name, not the storage name" do
42
- settings = Settings.new do
43
- let "U" => :username
44
- end
45
-
46
- ENV.clear
47
-
48
- pending "Needs to translate the setting name when telling you it's missing" do
49
- expect{settings.username}.to raise_error /Setting <username> not found/
50
- end
51
- end
52
- end
1
+ require "spec_helper"
2
+
3
+ describe "that you can translate storage names into whatever setting name you want" do
4
+ it "can supply mappings" do
5
+ settings = Settings.new do
6
+ let "U" => :username
7
+ let "P" => :password
8
+ end
9
+
10
+ ENV["U"] = "graeme.hay"
11
+ ENV["P"] = "allblacks"
12
+
13
+ expect(settings.username).to eql "graeme.hay"
14
+ expect(settings.password).to eql "allblacks"
15
+ end
16
+
17
+ it "you can map some and not others" do
18
+ settings_configured_with_username_mapping_only = Settings.new do
19
+ let "U" => :username
20
+ end
21
+
22
+ ENV["U"] = "graeme.hay"
23
+ ENV["P"] = "allblacks"
24
+
25
+ expect(settings_configured_with_username_mapping_only.username).to eql "graeme.hay"
26
+ expect(settings_configured_with_username_mapping_only.P).to eql "allblacks"
27
+ end
28
+
29
+ it "you can map none" do
30
+ settings_configured_with_nothing = Settings.new do
31
+
32
+ end
33
+
34
+ ENV["U"] = "graeme.hay"
35
+ ENV["P"] = "allblacks"
36
+
37
+ expect(settings_configured_with_nothing.U).to eql "graeme.hay"
38
+ expect(settings_configured_with_nothing.P).to eql "allblacks"
39
+ end
40
+
41
+ it "when the setting is not found it tells you the mapped name, not the storage name" do
42
+ settings = Settings.new do
43
+ let "U" => :username
44
+ end
45
+
46
+ ENV.clear
47
+
48
+ pending "Needs to translate the setting name when telling you it's missing" do
49
+ expect{settings.username}.to raise_error /Setting <username> not found/
50
+ end
51
+ end
52
+ end
@@ -1,39 +1,39 @@
1
- require "spec_helper"
2
-
3
- describe "settings that are either true or false" do
4
- let(:settings){Settings.new}
5
-
6
- before { ENV.clear }
7
-
8
- it "returns a flag when value is 'yes' or 'no'" do
9
- ENV["allowed"] = "yes"
10
- ENV["disallowed"] = "no"
11
-
12
- expect(settings.allowed?).to be_true
13
- expect(settings.disallowed?).to be_false
14
- end
15
-
16
- it "also supports 'on' and 'off'" do
17
- ENV["allowed"] = "on"
18
- ENV["disallowed"] = "off"
19
-
20
- expect(settings.allowed?).to be_true
21
- expect(settings.disallowed?).to be_false
22
- end
23
-
24
- it "any other value returns setting not found" do
25
- ENV["allowed"] = "xxx"
26
-
27
- expect{settings.allowed?}.to raise_error /Unable to convert setting <allowed> to flag/
28
- end
29
-
30
- it "accepts mapped setting names, too" do
31
- settings = Settings.new do
32
- let "V" => "verbose"
33
- end
34
-
35
- ENV["V"] = "yes"
36
-
37
- expect(settings.verbose?).to be_true
38
- end
39
- end
1
+ require "spec_helper"
2
+
3
+ describe "settings that are either true or false" do
4
+ let(:settings){Settings.new}
5
+
6
+ before { ENV.clear }
7
+
8
+ it "returns a flag when value is 'yes' or 'no'" do
9
+ ENV["allowed"] = "yes"
10
+ ENV["disallowed"] = "no"
11
+
12
+ expect(settings.allowed?).to be_true
13
+ expect(settings.disallowed?).to be_false
14
+ end
15
+
16
+ it "also supports 'on' and 'off'" do
17
+ ENV["allowed"] = "on"
18
+ ENV["disallowed"] = "off"
19
+
20
+ expect(settings.allowed?).to be_true
21
+ expect(settings.disallowed?).to be_false
22
+ end
23
+
24
+ it "any other value returns setting not found" do
25
+ ENV["allowed"] = "xxx"
26
+
27
+ expect{settings.allowed?}.to raise_error /Unable to convert setting <allowed> to flag/
28
+ end
29
+
30
+ it "accepts mapped setting names, too" do
31
+ settings = Settings.new do
32
+ let "V" => "verbose"
33
+ end
34
+
35
+ ENV["V"] = "yes"
36
+
37
+ expect(settings.verbose?).to be_true
38
+ end
39
+ end
@@ -1,39 +1,39 @@
1
- require "spec_helper"
2
-
3
- describe "default values for missing settings" do
4
- it "can be configured to use a default when setting is missing" do
5
- settings = Settings.new do
6
- default :colour, :to => "red"
7
- end
8
-
9
- expect(settings.colour).to eql "red"
10
- end
11
-
12
- it "can be overwritten -- the last set one wins" do
13
- settings = Settings.new do
14
- default :colour, :to => "red"
15
- default :colour, :to => "gold"
16
- end
17
-
18
- expect(settings.colour).to eql "gold"
19
- end
20
-
21
- it "you can default a mapped setting" do
22
- settings = Settings.new do
23
- let "C" => :colour
24
- default :colour, :to => "green"
25
- end
26
-
27
- expect(settings.colour).to eql "green"
28
- end
29
-
30
- it "is ignored if present elsewhere" do
31
- settings = Settings.new do
32
- default :colour, :to => "red"
33
- end
34
-
35
- ENV["colour"] = "pink"
36
-
37
- expect(settings.colour).to eql "pink"
38
- end
39
- end
1
+ require "spec_helper"
2
+
3
+ describe "default values for missing settings" do
4
+ it "can be configured to use a default when setting is missing" do
5
+ settings = Settings.new do
6
+ default :colour, :to => "red"
7
+ end
8
+
9
+ expect(settings.colour).to eql "red"
10
+ end
11
+
12
+ it "can be overwritten -- the last set one wins" do
13
+ settings = Settings.new do
14
+ default :colour, :to => "red"
15
+ default :colour, :to => "gold"
16
+ end
17
+
18
+ expect(settings.colour).to eql "gold"
19
+ end
20
+
21
+ it "you can default a mapped setting" do
22
+ settings = Settings.new do
23
+ let "C" => :colour
24
+ default :colour, :to => "green"
25
+ end
26
+
27
+ expect(settings.colour).to eql "green"
28
+ end
29
+
30
+ it "is ignored if present elsewhere" do
31
+ settings = Settings.new do
32
+ default :colour, :to => "red"
33
+ end
34
+
35
+ ENV["colour"] = "pink"
36
+
37
+ expect(settings.colour).to eql "pink"
38
+ end
39
+ end