figaro 0.7.0 → 1.0.0.rc1

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.
Files changed (54) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -1
  3. data/.travis.yml +23 -18
  4. data/CHANGELOG.md +98 -0
  5. data/CONTRIBUTING.md +48 -0
  6. data/Gemfile +4 -6
  7. data/{LICENSE → LICENSE.txt} +0 -0
  8. data/README.md +184 -61
  9. data/Rakefile +1 -12
  10. data/bin/figaro +5 -0
  11. data/doc/title.png +0 -0
  12. data/figaro.gemspec +9 -5
  13. data/gemfiles/rails30.gemfile +3 -4
  14. data/gemfiles/rails31.gemfile +3 -4
  15. data/gemfiles/rails32.gemfile +3 -4
  16. data/gemfiles/rails40.gemfile +3 -7
  17. data/gemfiles/rails41.gemfile +11 -0
  18. data/lib/figaro.rb +16 -29
  19. data/lib/figaro/application.rb +91 -0
  20. data/lib/figaro/cli.rb +24 -0
  21. data/lib/figaro/cli/heroku_set.rb +29 -0
  22. data/lib/figaro/cli/task.rb +27 -0
  23. data/lib/figaro/env.rb +36 -7
  24. data/lib/figaro/error.rb +12 -0
  25. data/lib/figaro/rails.rb +9 -0
  26. data/lib/figaro/rails/application.rb +21 -0
  27. data/lib/figaro/rails/railtie.rb +9 -0
  28. data/lib/figaro/{tasks.rake → rails/tasks.rake} +0 -0
  29. data/lib/generators/figaro/install/install_generator.rb +1 -1
  30. data/lib/generators/figaro/install/templates/application.yml +10 -6
  31. data/spec/figaro/application_spec.rb +258 -0
  32. data/spec/figaro/cli/heroku_set_spec.rb +62 -0
  33. data/spec/figaro/env_spec.rb +167 -35
  34. data/spec/figaro/rails/application_spec.rb +43 -0
  35. data/spec/figaro_spec.rb +74 -36
  36. data/spec/rails_spec.rb +66 -0
  37. data/spec/spec_helper.rb +6 -3
  38. data/spec/support/aruba.rb +19 -0
  39. data/spec/support/bin/heroku +5 -0
  40. data/spec/support/command_helpers.rb +17 -0
  41. data/spec/support/command_interceptor.rb +33 -0
  42. data/spec/support/random.rb +3 -0
  43. data/spec/support/reset.rb +13 -0
  44. metadata +88 -44
  45. data/features/rails.feature +0 -97
  46. data/features/step_definitions/bundler_steps.rb +0 -7
  47. data/features/step_definitions/common_steps.rb +0 -19
  48. data/features/step_definitions/rails_steps.rb +0 -12
  49. data/features/support/aruba.rb +0 -12
  50. data/features/support/env.rb +0 -8
  51. data/lib/figaro/railtie.rb +0 -16
  52. data/lib/figaro/tasks.rb +0 -28
  53. data/spec/figaro/tasks_spec.rb +0 -71
  54. data/spec/support/rake.rb +0 -11
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ module Figaro
4
+ module Rails
5
+ describe Application do
6
+ describe "#default_path" do
7
+ let!(:application) { Application.new }
8
+
9
+ it "defaults to config/application.yml in Rails.root" do
10
+ ::Rails.stub(root: Pathname.new("/path/to/app"))
11
+
12
+ expect {
13
+ ::Rails.stub(root: Pathname.new("/app"))
14
+ }.to change {
15
+ application.send(:default_path).to_s
16
+ }.from("/path/to/app/config/application.yml").to("/app/config/application.yml")
17
+ end
18
+
19
+ it "raises an error when Rails.root isn't set yet" do
20
+ ::Rails.stub(root: nil)
21
+
22
+ expect {
23
+ application.send(:default_path)
24
+ }.to raise_error(RailsNotInitialized)
25
+ end
26
+ end
27
+
28
+ describe "#default_environment" do
29
+ let!(:application) { Application.new }
30
+
31
+ it "defaults to Rails.env" do
32
+ ::Rails.stub(env: "development")
33
+
34
+ expect {
35
+ ::Rails.stub(env: "test")
36
+ }.to change {
37
+ application.send(:default_environment).to_s
38
+ }.from("development").to("test")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,63 +1,101 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Figaro do
4
- describe ".vars" do
5
- it "dumps and sorts env" do
6
- Figaro.stub(:env => Figaro::Env.from("HELLO" => "world", "FOO" => "bar"))
7
-
8
- expect(Figaro.vars).to eq("FOO=bar HELLO=world")
4
+ describe ".env" do
5
+ it "falls through to Figaro::ENV" do
6
+ expect(Figaro.env).to eq(Figaro::ENV)
9
7
  end
8
+ end
10
9
 
11
- it "allows access to a particular environment" do
12
- Figaro.stub(:env).with("development").
13
- and_return(Figaro::Env.from("HELLO" => "developers"))
14
- Figaro.stub(:env).with("production").
15
- and_return(Figaro::Env.from("HELLO" => "world"))
10
+ describe ".adapter" do
11
+ let(:adapter) { double(:adapter) }
16
12
 
17
- expect(Figaro.vars("development")).to eq("HELLO=developers")
18
- expect(Figaro.vars("production")).to eq("HELLO=world")
13
+ it "defaults to the generic application adapter" do
14
+ expect(Figaro.adapter).to eq(Figaro::Application)
19
15
  end
20
16
 
21
- it "escapes special characters" do
22
- Figaro.stub(:env => Figaro::Env.from("FOO" => "bar baz"))
23
-
24
- expect(Figaro.vars).to eq('FOO=bar\ baz')
17
+ it "is configurable" do
18
+ expect {
19
+ Figaro.adapter = adapter
20
+ }.to change {
21
+ Figaro.adapter
22
+ }.from(Figaro::Application).to(adapter)
25
23
  end
26
24
  end
27
25
 
28
- describe ".env" do
29
- it "is a Figaro env instance" do
30
- Figaro.stub(:raw => { "FOO" => "bar" })
26
+ describe ".application" do
27
+ let(:adapter) { double(:adapter) }
28
+ let(:application) { double(:application) }
29
+ let(:custom_application) { double(:custom_application) }
31
30
 
32
- expect(Figaro.env).to be_a(Figaro::Env)
31
+ before do
32
+ Figaro.stub(:adapter) { adapter }
33
+ adapter.stub(:new).with(no_args) { application }
33
34
  end
34
35
 
35
- it "allows access to a particular environment" do
36
- Figaro.stub(:raw).and_return(
37
- "development" => { "HELLO" => "developers" },
38
- "production" => { "HELLO" => "world" }
39
- )
36
+ it "defaults to a new adapter application" do
37
+ expect(Figaro.application).to eq(application)
38
+ end
40
39
 
41
- expect(Figaro.env(:development)).to eq("HELLO" => "developers")
42
- expect(Figaro.env(:production)).to eq("HELLO" => "world")
40
+ it "is configurable" do
41
+ expect {
42
+ Figaro.application = custom_application
43
+ }.to change {
44
+ Figaro.application
45
+ }.from(application).to(custom_application)
43
46
  end
47
+ end
44
48
 
45
- it "stringifies keys and values" do
46
- Figaro.stub(:raw => { :LUFTBALLOONS => 99 })
49
+ describe ".load" do
50
+ let(:application) { double(:application) }
47
51
 
48
- expect(Figaro.env).to eq("LUFTBALLOONS" => "99")
52
+ before do
53
+ Figaro.stub(:application) { application }
49
54
  end
50
55
 
51
- it "allows nil values" do
52
- Figaro.stub(:raw => { "FOO" => nil })
56
+ it "loads the application configuration" do
57
+ expect(application).to receive(:load).once.with(no_args)
53
58
 
54
- expect(Figaro.env).to eq("FOO" => nil)
59
+ Figaro.load
55
60
  end
61
+ end
56
62
 
57
- it "casts booleans to strings" do
58
- Figaro.stub(:raw => { "FOO" => true, "BAR" => false })
63
+ describe ".require" do
64
+ before do
65
+ ::ENV["foo"] = "bar"
66
+ ::ENV["hello"] = "world"
67
+ end
68
+
69
+ context "when no keys are missing" do
70
+ it "does nothing" do
71
+ expect {
72
+ Figaro.require("foo", "hello")
73
+ }.not_to raise_error
74
+ end
75
+
76
+ it "accepts an array" do
77
+ expect {
78
+ Figaro.require(["foo", "hello"])
79
+ }.not_to raise_error
80
+ end
81
+ end
59
82
 
60
- expect(Figaro.env).to eq("FOO" => "true", "BAR" => "false")
83
+ context "when keys are missing" do
84
+ it "raises an error for the missing keys" do
85
+ expect {
86
+ Figaro.require("foo", "goodbye", "baz")
87
+ }.to raise_error(Figaro::MissingKeys) { |error|
88
+ expect(error.message).not_to include("foo")
89
+ expect(error.message).to include("goodbye")
90
+ expect(error.message).to include("baz")
91
+ }
92
+ end
93
+
94
+ it "accepts an array" do
95
+ expect {
96
+ Figaro.require(["foo", "goodbye", "baz"])
97
+ }.to raise_error(Figaro::MissingKeys)
98
+ end
61
99
  end
62
100
  end
63
101
  end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe Figaro::Rails do
4
+ before do
5
+ run_simple(<<-CMD)
6
+ rails new example \
7
+ --skip-gemfile \
8
+ --skip-bundle \
9
+ --skip-keeps \
10
+ --skip-sprockets \
11
+ --skip-javascript \
12
+ --skip-test-unit \
13
+ --no-rc \
14
+ --quiet
15
+ CMD
16
+ cd("example")
17
+ end
18
+
19
+ describe "initialization" do
20
+ before do
21
+ write_file("config/application.yml", "foo: bar")
22
+ end
23
+
24
+ it "loads application.yml" do
25
+ run_simple("rails runner 'puts Figaro.env.foo'")
26
+
27
+ assert_partial_output("bar", all_stdout)
28
+ end
29
+
30
+ it "happens before database initialization" do
31
+ write_file("config/database.yml", <<-EOF)
32
+ development:
33
+ adapter: sqlite3
34
+ database: db/<%= ENV["foo"] %>.sqlite3
35
+ EOF
36
+
37
+ run_simple("rake db:migrate")
38
+
39
+ check_file_presence(["db/bar.sqlite3"], true)
40
+ end
41
+
42
+ it "happens before application configuration" do
43
+ insert_into_file_after("config/application.rb", /< Rails::Application$/, <<-EOL)
44
+ config.foo = ENV["foo"]
45
+ EOL
46
+
47
+ run_simple("rails runner 'puts Rails.application.config.foo'")
48
+
49
+ assert_partial_output("bar", all_stdout)
50
+ end
51
+ end
52
+
53
+ describe "rails generate figaro:install" do
54
+ it "generates application.yml" do
55
+ run_simple("rails generate figaro:install")
56
+
57
+ check_file_presence(["config/application.yml"], true)
58
+ end
59
+
60
+ it "ignores application.yml" do
61
+ run_simple("rails generate figaro:install")
62
+
63
+ check_file_content(".gitignore", %r(^/config/application\.yml$), true)
64
+ end
65
+ end
66
+ end
@@ -1,11 +1,14 @@
1
1
  if ENV["COVERAGE"]
2
- require "simplecov"
3
- SimpleCov.start { add_filter("spec") }
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
4
  end
5
5
 
6
6
  require "figaro"
7
- require "pathname"
8
7
 
8
+ require "bundler"
9
+ Bundler.require(:test)
10
+
11
+ require "pathname"
9
12
  ROOT = Pathname.new(File.expand_path("../..", __FILE__))
10
13
 
11
14
  Dir[ROOT.join("spec/support/**/*.rb")].each { |f| require f }
@@ -0,0 +1,19 @@
1
+ require "aruba/api"
2
+
3
+ module ArubaHelpers
4
+ def insert_into_file_after(file, pattern, addition)
5
+ content = prep_for_fs_check { IO.read(file) }
6
+ content.sub!(pattern, "\\0\n#{addition}")
7
+ overwrite_file(file, content)
8
+ end
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.include(Aruba::Api)
13
+ config.include(ArubaHelpers)
14
+
15
+ config.before do
16
+ @aruba_timeout_seconds = 60
17
+ FileUtils.rm_rf(current_dir)
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../../command_interceptor", __FILE__)
4
+
5
+ CommandInterceptor.intercept("heroku")
@@ -0,0 +1,17 @@
1
+ module CommandHelpers
2
+ def commands
3
+ CommandInterceptor.commands
4
+ end
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.include(CommandHelpers)
9
+
10
+ config.before(:suite) do
11
+ CommandInterceptor.setup
12
+ end
13
+
14
+ config.before do
15
+ CommandInterceptor.reset
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require "fileutils"
2
+ require "ostruct"
3
+ require "yaml"
4
+
5
+ module CommandInterceptor
6
+ class Command < OpenStruct
7
+ end
8
+
9
+ BIN_PATH = File.expand_path("../bin", __FILE__)
10
+ LOG_PATH = File.expand_path("../../../tmp/commands.yml", __FILE__)
11
+
12
+ def self.setup
13
+ ENV["PATH"] = "#{BIN_PATH}:#{ENV["PATH"]}"
14
+ end
15
+
16
+ def self.intercept(name)
17
+ FileUtils.mkdir_p(File.dirname(LOG_PATH))
18
+ FileUtils.touch(LOG_PATH)
19
+
20
+ command = { "env" => ENV.to_hash, "name" => name, "args" => ARGV }
21
+ commands = self.commands << command
22
+
23
+ File.write(LOG_PATH, YAML.dump(commands))
24
+ end
25
+
26
+ def self.commands
27
+ (File.exist?(LOG_PATH) && YAML.load_file(LOG_PATH) || []).map { |c| Command.new(c) }
28
+ end
29
+
30
+ def self.reset
31
+ FileUtils.rm_f(LOG_PATH)
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.order = "random"
3
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.configure do |config|
2
+ config.before(:suite) do
3
+ $original_env_keys = ::ENV.keys
4
+ end
5
+
6
+ config.before do
7
+ Figaro.adapter = nil
8
+ Figaro.application = nil
9
+
10
+ # Restore the original state of ENV for each test
11
+ ::ENV.keep_if { |k, _| $original_env_keys.include?(k) }
12
+ end
13
+ end
metadata CHANGED
@@ -1,85 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figaro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Richert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-27 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '1.0'
22
+ version: '5'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '1.0'
32
+ version: '5'
27
33
  - !ruby/object:Gem::Dependency
28
- name: rails
34
+ name: thor
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '3'
34
- - - <
37
+ - - "~>"
35
38
  - !ruby/object:Gem::Version
36
- version: '5'
39
+ version: '0.14'
37
40
  type: :runtime
38
41
  prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
- - - ! '>='
44
+ - - "~>"
42
45
  - !ruby/object:Gem::Version
43
- version: '3'
44
- - - <
46
+ version: '0.14'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
45
52
  - !ruby/object:Gem::Version
46
- version: '5'
53
+ version: '1.5'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.1'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.1'
47
75
  description: Simple, Heroku-friendly Rails app configuration using ENV and a single
48
76
  YAML file
49
77
  email: steve.richert@gmail.com
50
- executables: []
78
+ executables:
79
+ - figaro
51
80
  extensions: []
52
81
  extra_rdoc_files: []
53
82
  files:
54
- - .gitignore
55
- - .travis.yml
83
+ - ".gitignore"
84
+ - ".travis.yml"
85
+ - CHANGELOG.md
86
+ - CONTRIBUTING.md
56
87
  - Gemfile
57
- - LICENSE
88
+ - LICENSE.txt
58
89
  - README.md
59
90
  - Rakefile
60
- - features/rails.feature
61
- - features/step_definitions/bundler_steps.rb
62
- - features/step_definitions/common_steps.rb
63
- - features/step_definitions/rails_steps.rb
64
- - features/support/aruba.rb
65
- - features/support/env.rb
91
+ - bin/figaro
92
+ - doc/title.png
66
93
  - figaro.gemspec
67
94
  - gemfiles/rails30.gemfile
68
95
  - gemfiles/rails31.gemfile
69
96
  - gemfiles/rails32.gemfile
70
97
  - gemfiles/rails40.gemfile
98
+ - gemfiles/rails41.gemfile
71
99
  - lib/figaro.rb
100
+ - lib/figaro/application.rb
101
+ - lib/figaro/cli.rb
102
+ - lib/figaro/cli/heroku_set.rb
103
+ - lib/figaro/cli/task.rb
72
104
  - lib/figaro/env.rb
73
- - lib/figaro/railtie.rb
74
- - lib/figaro/tasks.rake
75
- - lib/figaro/tasks.rb
105
+ - lib/figaro/error.rb
106
+ - lib/figaro/rails.rb
107
+ - lib/figaro/rails/application.rb
108
+ - lib/figaro/rails/railtie.rb
109
+ - lib/figaro/rails/tasks.rake
76
110
  - lib/generators/figaro/install/install_generator.rb
77
111
  - lib/generators/figaro/install/templates/application.yml
112
+ - spec/figaro/application_spec.rb
113
+ - spec/figaro/cli/heroku_set_spec.rb
78
114
  - spec/figaro/env_spec.rb
79
- - spec/figaro/tasks_spec.rb
115
+ - spec/figaro/rails/application_spec.rb
80
116
  - spec/figaro_spec.rb
117
+ - spec/rails_spec.rb
81
118
  - spec/spec_helper.rb
82
- - spec/support/rake.rb
119
+ - spec/support/aruba.rb
120
+ - spec/support/bin/heroku
121
+ - spec/support/command_helpers.rb
122
+ - spec/support/command_interceptor.rb
123
+ - spec/support/random.rb
124
+ - spec/support/reset.rb
83
125
  homepage: https://github.com/laserlemon/figaro
84
126
  licenses:
85
127
  - MIT
@@ -90,29 +132,31 @@ require_paths:
90
132
  - lib
91
133
  required_ruby_version: !ruby/object:Gem::Requirement
92
134
  requirements:
93
- - - ! '>='
135
+ - - ">="
94
136
  - !ruby/object:Gem::Version
95
137
  version: '0'
96
138
  required_rubygems_version: !ruby/object:Gem::Requirement
97
139
  requirements:
98
- - - ! '>='
140
+ - - ">"
99
141
  - !ruby/object:Gem::Version
100
- version: '0'
142
+ version: 1.3.1
101
143
  requirements: []
102
144
  rubyforge_project:
103
- rubygems_version: 2.0.3
145
+ rubygems_version: 2.2.2
104
146
  signing_key:
105
147
  specification_version: 4
106
148
  summary: Simple Rails app configuration
107
149
  test_files:
108
- - features/rails.feature
109
- - features/step_definitions/bundler_steps.rb
110
- - features/step_definitions/common_steps.rb
111
- - features/step_definitions/rails_steps.rb
112
- - features/support/aruba.rb
113
- - features/support/env.rb
150
+ - spec/figaro/application_spec.rb
151
+ - spec/figaro/cli/heroku_set_spec.rb
114
152
  - spec/figaro/env_spec.rb
115
- - spec/figaro/tasks_spec.rb
153
+ - spec/figaro/rails/application_spec.rb
116
154
  - spec/figaro_spec.rb
155
+ - spec/rails_spec.rb
117
156
  - spec/spec_helper.rb
118
- - spec/support/rake.rb
157
+ - spec/support/aruba.rb
158
+ - spec/support/bin/heroku
159
+ - spec/support/command_helpers.rb
160
+ - spec/support/command_interceptor.rb
161
+ - spec/support/random.rb
162
+ - spec/support/reset.rb