a9n 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21f8c63dec2204f125358ccde13f47b549fcb504
4
- data.tar.gz: 812f362075f3155c1f91d1514b1fb04e61a9be05
3
+ metadata.gz: 14a5336e3c89478cdefd0df4a7c71dd78e809b10
4
+ data.tar.gz: 5ddb8cbb02e172e3bd26e43c2397ae0d49581a9a
5
5
  SHA512:
6
- metadata.gz: 847e440280de1c18814527281935fd658674e7b90bee168b445c57903d0fd14c83bf29c74cc38211998615eda96f4510fc377e0e40ce63279549db5d7d4508f4
7
- data.tar.gz: 38630688d8e2ab8ba68ca5b3341cd8d802a92c0f194aa582d6f5d023f5f68432177adb3cb2287e8823122b534e77673f109852a8b76002c8fdd08afc9362cd94
6
+ metadata.gz: 84e86886b37e5c7f785f6c9e9b0221aa05c9b0feced8f7992328d9bc475ff4842272d6011ef98cedb7153b289a40f63390e278d8a17ebde5647e71eccf3614b2
7
+ data.tar.gz: 4995758ee232692f671f8f944865712ff169bdb4ac0c166a0fe6ce0eebd95295f35909a6d35189dca44b5913c139565f58531309c8cf7ca37633a61f3c98a097
@@ -1,10 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
3
  - "1.9.3"
5
4
  - "2.0.0"
6
- - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
5
+ - jruby-19mode
9
6
  - rbx-19mode
10
- - ree
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
  gem 'rake'
5
- gem 'rspec'
6
- gem 'coveralls', :require => false
5
+ gem 'rspec', '~> 2.14.0.rc1'
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [codeclimate]: https://codeclimate.com/github/knapo/a9n
11
11
  [coveralls]: https://coveralls.io/r/knapo/a9n
12
12
 
13
- Simple tool for managing ruby/rails application configurations. Supports Rails 2.x, 3.x, 4.x.
13
+ Simple tool for managing extra configuration in ruby/rails apps. Supports Rails 2.x, 3.x, 4.x and Ruby 1.9, 2.0. For Ruby 1.8 use version < 1.0
14
14
 
15
15
  ## Installation
16
16
 
data/Rakefile CHANGED
@@ -8,4 +8,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
8
8
  t.rspec_opts = ['--profile', '--color']
9
9
  end
10
10
 
11
- task :default => :spec
11
+ task default: :spec
data/lib/a9n.rb CHANGED
@@ -18,7 +18,7 @@ module A9n
18
18
  end
19
19
 
20
20
  def env
21
- @env ||= local_app_env || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['APP_ENV']
21
+ @env ||= local_app_env || get_env_var('RAILS_ENV') || get_env_var('RACK_ENV') || get_env_var('APP_ENV')
22
22
  end
23
23
 
24
24
  def local_app_env
@@ -82,6 +82,14 @@ module A9n
82
82
  config.send(name, *args)
83
83
  end
84
84
 
85
+ def get_rails
86
+ defined?(Rails) ? Rails : nil
87
+ end
88
+
89
+ def get_env_var(name)
90
+ ENV[name]
91
+ end
92
+
85
93
  private
86
94
 
87
95
  def verify!(base, local)
@@ -90,9 +98,5 @@ module A9n
90
98
  raise MissingConfigurationVariables.new("Following variables are missing in your configuration file: #{missing_keys.join(',')}")
91
99
  end
92
100
  end
93
-
94
- def get_rails
95
- defined?(Rails) ? Rails : nil
96
- end
97
101
  end
98
102
  end
@@ -11,11 +11,7 @@ module A9n
11
11
  end
12
12
 
13
13
  def method_missing(name, *args)
14
- unless @table.key?(name.to_sym)
15
- raise NoSuchConfigurationVariable.new(name)
16
- end
17
-
18
- return @table[name.to_sym]
14
+ raise NoSuchConfigurationVariable.new(name)
19
15
  end
20
16
  end
21
17
  end
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -4,7 +4,7 @@ describe A9n do
4
4
  describe '.local_app' do
5
5
  context 'when rails not found' do
6
6
  before {
7
- described_class.should_receive(:get_rails).and_return(nil)
7
+ expect(described_class).to receive(:get_rails).and_return(nil)
8
8
  }
9
9
  specify {
10
10
  described_class.local_app.should be_nil
@@ -12,7 +12,7 @@ describe A9n do
12
12
  end
13
13
 
14
14
  context 'when custom non-rails app is being used' do
15
- let(:local_app) { stub(:env => 'test', :root => '/apps/a9n') }
15
+ let(:local_app) { double(:env => 'test', :root => '/apps/a9n') }
16
16
  before { described_class.local_app = local_app }
17
17
 
18
18
  specify { described_class.local_app.should == local_app }
@@ -22,7 +22,7 @@ describe A9n do
22
22
  end
23
23
 
24
24
  describe '.root' do
25
- let(:local_app) { stub(:env => 'test', :root => '/apps/a9n') }
25
+ let(:local_app) { double(:env => 'test', :root => '/apps/a9n') }
26
26
  before { described_class.local_app = local_app }
27
27
 
28
28
  context 'with custom path' do
@@ -57,9 +57,9 @@ describe A9n do
57
57
 
58
58
  context 'when no configuration file exists' do
59
59
  before do
60
- described_class.should_receive(:load_yml).with('config/configuration.yml.example').and_return(nil)
61
- described_class.should_receive(:load_yml).with('config/configuration.yml').and_return(nil)
62
- described_class.should_receive(:verify!).never
60
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(nil)
61
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(nil)
62
+ expect(described_class).to receive(:verify!).never
63
63
  end
64
64
  it 'raises expection' do
65
65
  lambda {
@@ -70,13 +70,14 @@ describe A9n do
70
70
 
71
71
  context 'when base configuration file exists' do
72
72
  before do
73
- described_class.should_receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
74
- described_class.should_receive(:load_yml).with('config/configuration.yml').and_return(nil)
75
- described_class.should_receive(:verify!).never
73
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
74
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(nil)
75
+ expect(described_class).to receive(:verify!).never
76
76
  described_class.load
77
77
  end
78
78
 
79
79
  its(:app_url) { should_not be_nil }
80
+ its(:app_url) { should == subject.fetch(:app_url) }
80
81
  specify {
81
82
  expect { subject.app_host }.to raise_error(described_class::NoSuchConfigurationVariable)
82
83
  }
@@ -84,9 +85,9 @@ describe A9n do
84
85
 
85
86
  context 'when local configuration file exists' do
86
87
  before do
87
- described_class.should_receive(:load_yml).with('config/configuration.yml.example').and_return(nil)
88
- described_class.should_receive(:load_yml).with('config/configuration.yml').and_return(local_sample_config)
89
- described_class.should_receive(:verify!).never
88
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(nil)
89
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(local_sample_config)
90
+ expect(described_class).to receive(:verify!).never
90
91
  described_class.load
91
92
  end
92
93
 
@@ -99,8 +100,8 @@ describe A9n do
99
100
  context 'when both local and base configuration file exists' do
100
101
  context 'with same data' do
101
102
  before do
102
- described_class.should_receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
103
- described_class.should_receive(:load_yml).with('config/configuration.yml').and_return(base_sample_config)
103
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
104
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(base_sample_config)
104
105
  described_class.load
105
106
  end
106
107
 
@@ -112,8 +113,8 @@ describe A9n do
112
113
 
113
114
  context 'with different data' do
114
115
  before do
115
- described_class.should_receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
116
- described_class.should_receive(:load_yml).with('config/configuration.yml').and_return(local_sample_config)
116
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
117
+ expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(local_sample_config)
117
118
  end
118
119
  it 'raises expection' do
119
120
  expect {
@@ -129,11 +130,11 @@ describe A9n do
129
130
  subject { described_class.load_yml(file_path) }
130
131
 
131
132
  before do
132
- described_class.should_receive(:root).at_least(:once).and_return(root)
133
+ expect(described_class).to receive(:root).at_least(:once).and_return(root)
133
134
  end
134
135
 
135
136
  context 'when file not exists' do
136
- before { described_class.should_receive(:env).never }
137
+ before { expect(described_class).to receive(:env).never }
137
138
  let(:file_path) { 'file_not_existing_in_universe.yml' }
138
139
 
139
140
  it 'returns nil' do
@@ -145,7 +146,7 @@ describe A9n do
145
146
  let(:file_path) { 'fixtures/configuration.yml'}
146
147
  before {
147
148
  ENV['DWARF'] = 'erbized dwarf'
148
- described_class.should_receive(:env).twice.and_return(env)
149
+ expect(described_class).to receive(:env).twice.and_return(env)
149
150
  }
150
151
 
151
152
  context 'and has data' do
@@ -178,4 +179,51 @@ describe A9n do
178
179
  end
179
180
  end
180
181
  end
182
+
183
+ describe '.env' do
184
+ before {
185
+ described_class.instance_variable_set(:@env, nil)
186
+ }
187
+
188
+ context 'local_app_env is set' do
189
+ before {
190
+ expect(described_class).to receive(:local_app).and_return(double(:env => 'dwarf_env')).exactly(3).times
191
+ expect(described_class).to receive(:get_env_var).never
192
+ }
193
+ its(:env) { should == 'dwarf_env' }
194
+ end
195
+
196
+ context "when APP_ENV is set" do
197
+ before {
198
+ expect(described_class).to receive(:local_app_env).and_return(nil)
199
+ expect(described_class).to receive(:get_env_var).with('RAILS_ENV').and_return(nil)
200
+ expect(described_class).to receive(:get_env_var).with('RACK_ENV').and_return(nil)
201
+ expect(described_class).to receive(:get_env_var).with('APP_ENV').and_return('dwarf_env')
202
+ }
203
+ its(:env) { should == 'dwarf_env' }
204
+ end
205
+ end
206
+
207
+ describe '.get_env_var' do
208
+ before { ENV['DWARF'] = 'little dwarf' }
209
+ it { described_class.get_env_var('DWARF').should == 'little dwarf'}
210
+ it { described_class.get_env_var('IS_DWARF').should be_nil}
211
+ end
212
+
213
+ describe '.get_rails' do
214
+ context 'when defined' do
215
+ before {
216
+ Object.const_set(:Rails, Module.new)
217
+ }
218
+ after {
219
+ Object.send(:remove_const, :Rails)
220
+ }
221
+ it {
222
+ described_class.get_rails.should be_kind_of(Module)
223
+ }
224
+ end
225
+ context 'when not defined' do
226
+ it { described_class.get_rails.should be_nil }
227
+ end
228
+ end
181
229
  end
@@ -1,11 +1,19 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_filter '/spec/'
10
+ end
11
+
1
12
  require 'rubygems'
2
13
  require 'bundler/setup'
3
14
 
4
15
  require 'a9n'
5
16
 
6
- require 'coveralls'
7
- Coveralls.wear!
8
-
9
17
  RSpec.configure do |config|
10
18
  config.order = "random"
11
19
  config.color_enabled = true
@@ -11,6 +11,8 @@ describe A9n::Struct do
11
11
  })
12
12
  }
13
13
 
14
+ its(:keys) { should == [:non_empty_dwarf, :nil_dwarf, :false_dwarf, :true_dwarf, :hash_dwarf] }
15
+
14
16
  it 'gets non-empty value' do
15
17
  subject.non_empty_dwarf.should == 'dwarf'
16
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a9n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik