forj 0.0.39 → 0.0.40

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.
@@ -23,12 +23,13 @@ $LOAD_PATH << './lib'
23
23
 
24
24
  require 'forj-config.rb' # Load class ForjConfig
25
25
  require 'log.rb' # Load default loggers
26
+ require 'ansi'
26
27
 
27
28
  include Logging
28
29
 
29
30
  $FORJ_LOGGER=ForjLog.new('forj-rspec.log', Logger::FATAL)
30
31
 
31
- describe "class: forj-config" do
32
+ describe "class: forj-config," do
32
33
  context "when creating a new instance" do
33
34
 
34
35
  it 'should be loaded' do
@@ -42,39 +43,36 @@ describe "class: forj-config" do
42
43
  before(:all) do
43
44
  @config=ForjConfig.new()
44
45
  end
45
-
46
+
46
47
  it 'should be able to create a key/value in local config' do
47
48
  @config.LocalSet('test1','value')
48
- expect(@config.yConfig['default']['test1']).to eq('value')
49
+ expect(@config.LocalGet('test1')).to eq('value')
49
50
  end
50
51
 
51
52
  it 'should be able to remove the previously created key/value from local config' do
52
53
  @config.LocalDel('test1')
53
- expect(@config.yConfig['default'].key?('test1')).to equal(false)
54
+ expect(@config.exist?('test1')).to equal(false)
54
55
  end
55
- end
56
+ end
56
57
 
57
-
58
58
  context "while updating local config file, forj-config" do
59
59
  before(:all) do
60
- @config=ForjConfig.new()
60
+ @config=ForjConfig.new()
61
61
  end
62
-
62
+
63
63
  after(:all) do
64
64
  @config.LocalDel('test1')
65
65
  @config.SaveConfig()
66
- end
66
+ end
67
67
 
68
68
  it 'should save a key/value in local config' do
69
69
  @config.LocalSet('test1','value')
70
70
  expect(@config.SaveConfig()).to equal(true)
71
- end
72
-
73
- it 'should get the saved value from local config' do
71
+
74
72
  oConfig=ForjConfig.new()
75
- expect(@config.yConfig['default']['test1']).to eq('value')
73
+ expect(@config.LocalGet('test1')).to eq('value')
76
74
  end
77
-
75
+
78
76
  end
79
77
 
80
78
  context "With another config file - test1.yaml, forj-config" do
@@ -87,15 +85,15 @@ describe "class: forj-config" do
87
85
  @config=ForjConfig.new('test.yaml')
88
86
  @config2=ForjConfig.new('test1.yaml')
89
87
  end
90
-
88
+
91
89
  after(:all) do
92
90
  File.delete(File.expand_path('~/.forj/test1.yaml'))
93
- end
91
+ end
94
92
 
95
93
  it 'won\'t create a new file If we request to load \'test.yaml\'' do
96
94
  expect(File.exists?(File.expand_path('~/.forj/test.yaml'))).to equal(false)
97
95
  end
98
-
96
+
99
97
  it 'will load the default config file if we request to load \'test.yaml\'' do
100
98
  expect(File.basename(@config.sConfigName)).to eq('config.yaml')
101
99
  end
@@ -108,10 +106,114 @@ describe "class: forj-config" do
108
106
  @config2.LocalSet('test2','value')
109
107
  expect(@config2.SaveConfig()).to equal(true)
110
108
  config3=ForjConfig.new('test1.yaml')
111
- expect(config3.yConfig['default']['test2']).to eq('value')
109
+ expect(config3.LocalGet('test2')).to eq('value')
112
110
  end
113
111
 
114
-
115
112
  end
116
113
 
114
+ context "with get/set/exists?," do
115
+ before(:all) do
116
+ @config=ForjConfig.new()
117
+ @url = @config.get('maestro_url')
118
+ end
119
+
120
+ it 'can set and get data,' do
121
+ expect(@config.set(nil, nil)).to equal(false)
122
+ expect(@config.set(:test, nil)).to equal(true)
123
+ expect(@config.get(:test)).to equal(nil)
124
+
125
+ expect(@config.set(:test, 'data')).to equal(true)
126
+ expect(@config.get(:test)).to eq('data')
127
+ end
128
+
129
+ context 'from defaults,' do
130
+ it 'can get application defaults' do
131
+ expect(@config.get('maestro_url').class).to equal(String)
132
+ expect(@config.getAppDefault('default', 'maestro_url').class).to equal(String)
133
+ expect(@config.getAppDefault(:description, 'FORJ_HPC').class).to equal(String)
134
+
135
+ end
136
+ it 'can get Local defaults instead of application' do
137
+ expect(@config.LocalSet('maestro_url','local')).to equal(true)
138
+ expect(@config.LocalGet('maestro_url')).to eq('local')
139
+ expect(@config.get('maestro_url')).to eq('local')
140
+ end
141
+
142
+ it 'can get runtime defaults instead of Local/application' do
143
+ expect(@config.set('maestro_url', 'runtime')).to equal(true)
144
+ expect(@config.get('maestro_url')).to eq('runtime')
145
+ expect(@config.LocalGet('maestro_url')).to eq('local')
146
+ end
147
+
148
+ it 'can get runtime defaults instead of application' do
149
+ expect(@config.LocalDel('maestro_url')).to equal(true)
150
+ expect(@config.get('maestro_url')).to eq('runtime')
151
+ expect(@config.LocalGet('maestro_url')).to equal(nil)
152
+ end
153
+
154
+ it 'can get defaults if no key' do
155
+ expect(@config.set(:test1, nil)).to equal(true)
156
+ expect(@config.get(:test1, nil, 'default')).to eq('default')
157
+ expect(@config.get(:test1, nil, nil)).to equal(nil)
158
+ expect(@config.set('maestro_url',nil)).to equal(true)
159
+ expect(@config.get('maestro_url')).to eq(@url)
160
+ end
161
+ end
162
+
163
+ context 'with intermediates,' do
164
+ before(:all) do
165
+ @yYAML1={ 'maestro_url' => 'url1' }
166
+ @aArray1=[]
167
+ @aArray1[0]={ 'maestro_url' => 'url2' }
168
+ @aArray1[1]=@yYAML1
169
+ @aArray2=[]
170
+ @aArray2[0] = @aArray1[1]
171
+ @aArray2[1] = @aArray1[0]
172
+ end
173
+
174
+ it 'can get data from one hash' do
175
+ expect(@config.get('maestro_url', @yYAML1)).to eq('url1')
176
+ @config.set('maestro_url', 'runtime')
177
+ expect(@config.get('maestro_url', @yYAML1)).to eq('runtime')
178
+ end
179
+
180
+ it 'can get data from several hashes' do
181
+ @config.set('maestro_url', nil)
182
+ expect(@config.get('maestro_url', @aArray1)).to eq('url2')
183
+ expect(@config.get('maestro_url', @aArray2)).to eq('url1')
184
+ end
185
+ end
186
+ end
187
+ end
188
+
189
+ describe 'Recursive Hash functions,' do
190
+ context "With recursive Hash functions" do
191
+ it 'can create a 3 levels of hash' do
192
+ yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
193
+ expect(yYAML[:level1][:level2][:level3]).to eq('level4')
194
+ end
195
+
196
+ it 'can add a 3 levels of hash in an existing hash' do
197
+ yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
198
+ yYAML = rhSet(yYAML, 'level1.1', :level1_1)
199
+ expect(yYAML[:level1][:level2][:level3]).to eq('level4')
200
+ expect(yYAML[:level1_1]).to eq('level1.1')
201
+ end
202
+
203
+ it 'can get each levels of hash data' do
204
+ yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
205
+ expect(rhGet(yYAML, :level1).class).to equal(Hash)
206
+ expect(rhGet(yYAML, :level1, :level2).class).to equal(Hash)
207
+ expect(rhGet(yYAML, :level1, :level2, :level3).class).to equal(String)
208
+ end
209
+
210
+ it 'can check existence of each levels of hash data' do
211
+ yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
212
+ expect(rhExist?(yYAML, :level1)).to eq(1)
213
+ expect(rhExist?(yYAML, :level1, :level2)).to eq(2)
214
+ expect(rhExist?(yYAML, :level1, :level2, :level3)).to eq(3)
215
+ expect(rhExist?(yYAML, :level1_1, :level2, :level3)).to eq(0)
216
+
217
+ end
218
+ end
117
219
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-01 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -160,6 +160,7 @@ files:
160
160
  - lib/log.rb
161
161
  - lib/helpers.rb
162
162
  - lib/forj-config.rb
163
+ - lib/forj-account.rb
163
164
  - spec/boot_spec.rb
164
165
  - spec/connection_spec.rb
165
166
  - spec/down_spec.rb