yacht 0.1.2 → 0.2.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.
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yacht::Loader do
4
+ subject { Yacht::Loader }
5
+
6
+ describe :classy_struct_instance do
7
+ it "should create a new ClassyStruct" do
8
+ ClassyStruct.should_receive(:new)
9
+ subject.classy_struct_instance
10
+ end
11
+ end
12
+
13
+ describe :to_classy_struct do
14
+ it "creates a ClassyStruct based on to_hash" do
15
+ subject.stub(:to_hash).and_return(:foo => 'bar')
16
+ subject.to_classy_struct.foo.should == "bar"
17
+ end
18
+
19
+ # ClassyStruct improves performance by adding accessors to the instance object
20
+ # If the instance is not reused, there is no advantage to ClassyStruct over OpenStruct
21
+ it "reuses the instance of ClassyStruct on subsequent calls" do
22
+ first_obj = subject.classy_struct_instance
23
+ second_obj = subject.classy_struct_instance
24
+
25
+ first_obj.object_id.should == second_obj.object_id.should
26
+ end
27
+
28
+ it "passes options to to_hash" do
29
+ subject.should_receive(:to_hash).with({:my => :awesome_option})
30
+
31
+ subject.to_classy_struct({:my => :awesome_option})
32
+ end
33
+
34
+ it "raises a custom error if ClassyStruct cannot be created" do
35
+ subject.stub!(:to_hash).and_raise("some funky error")
36
+
37
+ expect {
38
+ subject.to_classy_struct
39
+ }.to raise_error(Yacht::LoadError, /some funky error/)
40
+ end
41
+
42
+ it "does not intercept YachtLoader custom errors" do
43
+ subject.stub!(:to_hash).and_raise Yacht::LoadError.new("custom error message")
44
+
45
+ expect {
46
+ subject.to_classy_struct
47
+ }.to raise_error(Yacht::LoadError, "custom error message")
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ describe Yacht do
54
+ subject { Yacht }
55
+ after do
56
+ Yacht.instance_variable_set(:@_hash, nil)
57
+ Yacht.instance_variable_set(:@_classy_struct, nil)
58
+ end
59
+
60
+ context "just like a classy struct instance" do
61
+ it "should retrieve values by key" do
62
+ Yacht::Loader.stub(:to_hash).and_return(:foo => 'bar')
63
+
64
+ Yacht.foo.should == 'bar'
65
+ end
66
+
67
+ it "should return nil for nonexistent keys" do
68
+ Yacht::Loader.stub(:to_hash).and_return(:foo => 'bar')
69
+
70
+ Yacht.snafu.should be_nil
71
+ end
72
+
73
+ it "should handles nested hashes" do
74
+ Yacht::Loader.stub(:to_hash).and_return({:foo => {:bar => 'baz'}})
75
+
76
+ Yacht.foo.to_hash.should == {:bar => 'baz'}
77
+ Yacht.foo.bar.should == 'baz'
78
+ Yacht.foo.fu.should be_nil
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,215 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yacht::Loader do
4
+ subject{ Yacht::Loader }
5
+
6
+ let(:mock_base_config) do
7
+ {
8
+ 'default' => {
9
+ :color_of_the_day => 'orange',
10
+ :super_secret_info => 'swordfish'
11
+ },
12
+ 'wacky' => {
13
+ :color_of_the_day => 'purple',
14
+ :super_secret_info => 'mackerel',
15
+ }
16
+ }
17
+ end
18
+
19
+ describe :to_hash do
20
+ before do
21
+ subject.stub(:base_config).and_return(mock_base_config)
22
+ subject.stub(:local_config).and_return({})
23
+ subject.stub(:whitelist).and_return([:color_of_the_day])
24
+ end
25
+
26
+ it "returns all keys by default" do
27
+ subject.to_hash.should == mock_base_config['default']
28
+ end
29
+
30
+ it "only returns keys included in whitelist when :apply_whitelist? option is true" do
31
+ subject.to_hash(:apply_whitelist? => true).should == {:color_of_the_day => 'orange'}
32
+ end
33
+
34
+ it "allows selection of the environment by passing an :env param" do
35
+ subject.to_hash(:env => 'wacky').should == mock_base_config['wacky']
36
+ end
37
+
38
+ it "raises an error if an environment is requested that doesn't exist" do
39
+ expect {
40
+ subject.environment = 'nonexistent'
41
+ subject.to_hash
42
+ }.to raise_error( Yacht::LoadError, /does not exist/)
43
+ end
44
+
45
+ context "with inheritance" do
46
+ let(:mock_base_config_with_inheritance) do
47
+ {
48
+ 'default' => {
49
+ :doggies => {
50
+ 'lassie' => 'nice',
51
+ 'cujo' => 'mean'
52
+ }
53
+ },
54
+ 'papa' => {
55
+ :use_ssl? => false,
56
+ :doggies => {
57
+ 'benji' => 'smart'
58
+ }
59
+ },
60
+ 'kid' => {
61
+ '_parent' => 'papa',
62
+ :doggies => {
63
+ 'cerberus' => '3-headed'
64
+ }
65
+ }
66
+ }
67
+ end
68
+
69
+ before do
70
+ subject.stub(:base_config).and_return(mock_base_config_with_inheritance)
71
+ subject.environment = 'kid'
72
+ end
73
+
74
+ it "transfer values from _parent environment if _parent is set" do
75
+ subject.to_hash[:use_ssl?].should be_false
76
+ end
77
+
78
+ it "merges the hashes recursively" do
79
+ subject.to_hash[:doggies].should == {
80
+ 'lassie' => 'nice',
81
+ 'cujo' => 'mean',
82
+ 'benji' => 'smart',
83
+ 'cerberus' => '3-headed'
84
+ }
85
+ end
86
+ end
87
+ end
88
+
89
+ describe :all do
90
+ it "merges configuration for named environment onto defaults" do
91
+ subject.stub(:base_config).and_return({
92
+ 'default' => {
93
+ :color_of_the_day => 'orange',
94
+ },
95
+ 'wacky' => {
96
+ :color_of_the_day => 'purple',
97
+ }
98
+ })
99
+
100
+ subject.environment = 'wacky'
101
+ subject.to_hash[:color_of_the_day].should == 'purple'
102
+ end
103
+ end
104
+
105
+ describe :base_config do
106
+ it "calls load_config_file" do
107
+ subject.should_receive(:load_config_file).with(:base).and_return('foo')
108
+
109
+ subject.base_config
110
+ end
111
+
112
+ it "raises an error if load_config_file returns nil" do
113
+ subject.stub(:load_config_file).with(:base).and_return(nil)
114
+ expect {
115
+ subject.base_config
116
+ }.to raise_error(Yacht::LoadError, "Couldn't load base config")
117
+ end
118
+ end
119
+
120
+ describe :local_config do
121
+ it "calls load_config_file" do
122
+ subject.should_receive(:load_config_file).with(:local).and_return('local_foo')
123
+
124
+ subject.local_config
125
+ end
126
+
127
+ it "returns an empty hash if load_config_file returns nil" do
128
+ subject.stub(:load_config_file).with(:local).and_return(nil)
129
+ subject.local_config.should == {}
130
+ end
131
+
132
+ # Handling of empty local.yml file
133
+ # YAML.load("")
134
+ # => false
135
+ it "returns an empty hash if load_config_file returns false" do
136
+ subject.stub(:load_config_file).with(:local).and_return(false)
137
+ subject.local_config.should == {}
138
+ end
139
+ end
140
+
141
+ describe :whitelist do
142
+ # before do
143
+ # subject.stub(:base_config).and_return(mock_base_config)
144
+ # subject.stub(:local_config).and_return({})
145
+ # subject.stub(:whitelist).and_return([:color_of_the_day])
146
+ # end
147
+
148
+ it "raises an error if load_config_file returns nil" do
149
+ subject.stub(:load_config_file).with(:whitelist, :expect_to_load => Array).and_return(nil)
150
+
151
+ expect {
152
+ subject.whitelist
153
+ }.to raise_error( Yacht::LoadError, "Couldn't load whitelist")
154
+ end
155
+
156
+ it "expects load_config_file to return an Array" do
157
+ subject.should_receive(:load_config_file).with(:whitelist, :expect_to_load => Array).and_return([])
158
+
159
+ subject.whitelist
160
+ end
161
+ end
162
+
163
+ describe :config_file_for do
164
+ it "returns the full file path for the following config files: base, local & whitelist" do
165
+ %w(base local whitelist).each do |config_file|
166
+ subject.should_receive(:full_file_path_for_config).with(config_file)
167
+
168
+ subject.config_file_for(config_file)
169
+ end
170
+ end
171
+
172
+ it "raises an error if the config file is not found" do
173
+ expect {
174
+ subject.config_file_for(:foo)
175
+ }.to raise_error( Yacht::LoadError, "foo is not a valid config type")
176
+ end
177
+ end
178
+
179
+ describe :load_config_file do
180
+ it "loads the specified file" do
181
+ subject.stub(:config_file_for).with(:base).and_return('base_foo')
182
+ subject.stub(:_load_config_file).with('base_foo').and_return('base_bar')
183
+ subject.send(:load_config_file, :base, :expect_to_load => String).should == "base_bar"
184
+ end
185
+
186
+ it "raises an error if opening the file leads to an exception" do
187
+ subject.stub(:config_file_for).and_raise(StandardError.new("my_unique_error_message"))
188
+
189
+ expect {
190
+ subject.send(:load_config_file, "some file")
191
+ }.to raise_error( Yacht::LoadError, %r{ERROR: loading.+my_unique_error_message} )
192
+ end
193
+
194
+ it "raises an error if :expect_to_load param is passed but does not match loaded object" do
195
+ subject.stub(:config_file_for).with(:foo).and_return('foo_file')
196
+ subject.stub(:_load_config_file).with('foo_file').and_return(Hash.new) # notice the underscore!
197
+ expect {
198
+ subject.send(:load_config_file, :foo, :expect_to_load => Array)
199
+ }.to raise_error( Yacht::LoadError, "foo_file must contain Array (got Hash)" )
200
+ end
201
+
202
+ end
203
+
204
+ context "checks environment and sets sensible defaults" do
205
+ it "sets the environment to 'default'" do
206
+ subject.environment.should == "default"
207
+ end
208
+ end
209
+ end
210
+
211
+ describe YachtLoader do
212
+ it "should alias YachtLoader to Yacht::Loader for backwards compatibility" do
213
+ ::YachtLoader.should == Yacht::Loader
214
+ end
215
+ end
@@ -1,8 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Rails support" do
4
+ subject { Yacht::Loader }
5
+
4
6
  before do
5
- require "yacht_loader/rails"
7
+ require "yacht/rails"
6
8
  @yacht_dir = "/path/to/rails/config/yacht"
7
9
  end
8
10
 
@@ -13,7 +15,7 @@ describe "Rails support" do
13
15
  it "uses the current rails environment by default" do
14
16
  Rails.should_receive(:env)
15
17
 
16
- YachtLoader.environment
18
+ subject.environment
17
19
  end
18
20
  end
19
21
 
@@ -21,17 +23,17 @@ describe "Rails support" do
21
23
  it "uses config/yacht by default" do
22
24
  Rails.stub_chain(:root, :join).and_return(@yacht_dir)
23
25
 
24
- YachtLoader.dir.should == @yacht_dir
26
+ subject.dir.should == @yacht_dir
25
27
  end
26
28
  end
27
29
 
28
30
  describe :full_file_path_for_config do
29
31
  it "calls dir.join" do
30
32
  fake_dir = stub("dir stub")
31
- YachtLoader.stub(:dir).and_return(fake_dir)
33
+ subject.stub(:dir).and_return(fake_dir)
32
34
  fake_dir.should_receive(:join).with("some.yml")
33
35
 
34
- YachtLoader.full_file_path_for_config("some")
36
+ subject.full_file_path_for_config("some")
35
37
  end
36
38
  end
37
39
  end
data/yacht.gemspec CHANGED
@@ -2,13 +2,13 @@
2
2
  lib = File.expand_path('../lib/', __FILE__)
3
3
  $:.unshift lib unless $:.include?(lib)
4
4
 
5
- require 'yacht_loader/version'
5
+ require 'yacht/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "yacht"
9
- s.version = YachtLoader::VERSION
9
+ s.version = Yacht::VERSION
10
10
  s.authors = ["Mani Tadayon", "Rico Rodriquez Collins"]
11
- s.description = "Yacht is Yet Another Application Configuration Helper Tool."
11
+ s.description = "Yacht is Yet Another Configuration Helper Tool."
12
12
  s.summary = "yacht-#{s.version}"
13
13
  s.email = ["mtadayon@atti.com", "rcollins@atti.com"]
14
14
  s.homepage = "https://github.com/attinteractive/yacht"
@@ -17,9 +17,13 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency "classy_struct", ">= 0.3.2"
19
19
 
20
+ s.add_development_dependency "gherkin", '~> 2.3.0'
21
+ s.add_development_dependency "cucumber", '>= 0.10.0'
22
+ s.add_development_dependency 'aruba'
20
23
  s.add_development_dependency "rspec", '>= 2.6.0'
21
24
  s.add_development_dependency "simplecov", '>= 0.4.1'
22
25
 
26
+
23
27
  s.required_rubygems_version = ">= 1.3.7"
24
28
  s.files = `git ls-files`.split("\n")
25
29
  s.test_files = `git ls-files -- spec/*`.split("\n")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yacht
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mani Tadayon
@@ -11,7 +11,8 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-20 00:00:00 Z
14
+ date: 2011-06-16 00:00:00 -07:00
15
+ default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: classy_struct
@@ -25,28 +26,61 @@ dependencies:
25
26
  type: :runtime
26
27
  version_requirements: *id001
27
28
  - !ruby/object:Gem::Dependency
28
- name: rspec
29
+ name: gherkin
29
30
  prerelease: false
30
31
  requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 2.3.0
37
+ type: :development
38
+ version_requirements: *id002
39
+ - !ruby/object:Gem::Dependency
40
+ name: cucumber
41
+ prerelease: false
42
+ requirement: &id003 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.0
48
+ type: :development
49
+ version_requirements: *id003
50
+ - !ruby/object:Gem::Dependency
51
+ name: aruba
52
+ prerelease: false
53
+ requirement: &id004 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ type: :development
60
+ version_requirements: *id004
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ prerelease: false
64
+ requirement: &id005 !ruby/object:Gem::Requirement
31
65
  none: false
32
66
  requirements:
33
67
  - - ">="
34
68
  - !ruby/object:Gem::Version
35
69
  version: 2.6.0
36
70
  type: :development
37
- version_requirements: *id002
71
+ version_requirements: *id005
38
72
  - !ruby/object:Gem::Dependency
39
73
  name: simplecov
40
74
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
75
+ requirement: &id006 !ruby/object:Gem::Requirement
42
76
  none: false
43
77
  requirements:
44
78
  - - ">="
45
79
  - !ruby/object:Gem::Version
46
80
  version: 0.4.1
47
81
  type: :development
48
- version_requirements: *id003
49
- description: Yacht is Yet Another Application Configuration Helper Tool.
82
+ version_requirements: *id006
83
+ description: Yacht is Yet Another Configuration Helper Tool.
50
84
  email:
51
85
  - mtadayon@atti.com
52
86
  - rcollins@atti.com
@@ -61,22 +95,34 @@ files:
61
95
  - .gitignore
62
96
  - .rspec
63
97
  - .rvmrc
98
+ - .yardopts
64
99
  - Gemfile
65
100
  - LICENSE
66
101
  - README.rdoc
67
102
  - Rakefile
103
+ - features/load.feature
104
+ - features/missing_yaml_files.feature
105
+ - features/step_definitions/aruba_extension_steps.rb
106
+ - features/step_definitions/error_handling_steps.rb
107
+ - features/step_definitions/loader_steps.rb
108
+ - features/support/cleanup.rb
109
+ - features/support/env.rb
110
+ - gem_tasks/cucumber.rake
68
111
  - gem_tasks/spec.rake
69
112
  - lib/monkeypatches/hash.rb
70
113
  - lib/yacht.rb
71
- - lib/yacht_loader/base.rb
72
- - lib/yacht_loader/classy_struct.rb
73
- - lib/yacht_loader/rails.rb
74
- - lib/yacht_loader/version.rb
114
+ - lib/yacht/base.rb
115
+ - lib/yacht/classy_struct.rb
116
+ - lib/yacht/loader.rb
117
+ - lib/yacht/rails.rb
118
+ - lib/yacht/version.rb
75
119
  - spec/spec_helper.rb
76
- - spec/yacht_loader/base_spec.rb
77
- - spec/yacht_loader/classy_struct_spec.rb
78
- - spec/yacht_loader/rails_spec.rb
120
+ - spec/yacht/base_spec.rb
121
+ - spec/yacht/classy_struct_spec.rb
122
+ - spec/yacht/loader_spec.rb
123
+ - spec/yacht/rails_spec.rb
79
124
  - yacht.gemspec
125
+ has_rdoc: true
80
126
  homepage: https://github.com/attinteractive/yacht
81
127
  licenses: []
82
128
 
@@ -100,12 +146,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
146
  requirements: []
101
147
 
102
148
  rubyforge_project:
103
- rubygems_version: 1.7.2
149
+ rubygems_version: 1.3.9.1
104
150
  signing_key:
105
151
  specification_version: 3
106
- summary: yacht-0.1.2
152
+ summary: yacht-0.2.0
107
153
  test_files:
108
154
  - spec/spec_helper.rb
109
- - spec/yacht_loader/base_spec.rb
110
- - spec/yacht_loader/classy_struct_spec.rb
111
- - spec/yacht_loader/rails_spec.rb
155
+ - spec/yacht/base_spec.rb
156
+ - spec/yacht/classy_struct_spec.rb
157
+ - spec/yacht/loader_spec.rb
158
+ - spec/yacht/rails_spec.rb
@@ -1,15 +0,0 @@
1
- require 'classy_struct'
2
-
3
- class YachtLoader
4
- class << self
5
- def classy_struct_instance
6
- @classy_struct_instance ||= ClassyStruct.new
7
- end
8
-
9
- def to_classy_struct(opts={})
10
- classy_struct_instance.new( self.to_hash(opts) )
11
- rescue StandardError => e
12
- raise LoadError.new("Error creating ClassyStruct: #{e.message}")
13
- end
14
- end
15
- end
@@ -1,3 +0,0 @@
1
- class YachtLoader
2
- VERSION = "0.1.2"
3
- end