figaro 0.7.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +1 -1
- data/.travis.yml +23 -18
- data/CHANGELOG.md +98 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +4 -6
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.md +184 -61
- data/Rakefile +1 -12
- data/bin/figaro +5 -0
- data/doc/title.png +0 -0
- data/figaro.gemspec +9 -5
- data/gemfiles/rails30.gemfile +3 -4
- data/gemfiles/rails31.gemfile +3 -4
- data/gemfiles/rails32.gemfile +3 -4
- data/gemfiles/rails40.gemfile +3 -7
- data/gemfiles/rails41.gemfile +11 -0
- data/lib/figaro.rb +16 -29
- data/lib/figaro/application.rb +91 -0
- data/lib/figaro/cli.rb +24 -0
- data/lib/figaro/cli/heroku_set.rb +29 -0
- data/lib/figaro/cli/task.rb +27 -0
- data/lib/figaro/env.rb +36 -7
- data/lib/figaro/error.rb +12 -0
- data/lib/figaro/rails.rb +9 -0
- data/lib/figaro/rails/application.rb +21 -0
- data/lib/figaro/rails/railtie.rb +9 -0
- data/lib/figaro/{tasks.rake → rails/tasks.rake} +0 -0
- data/lib/generators/figaro/install/install_generator.rb +1 -1
- data/lib/generators/figaro/install/templates/application.yml +10 -6
- data/spec/figaro/application_spec.rb +258 -0
- data/spec/figaro/cli/heroku_set_spec.rb +62 -0
- data/spec/figaro/env_spec.rb +167 -35
- data/spec/figaro/rails/application_spec.rb +43 -0
- data/spec/figaro_spec.rb +74 -36
- data/spec/rails_spec.rb +66 -0
- data/spec/spec_helper.rb +6 -3
- data/spec/support/aruba.rb +19 -0
- data/spec/support/bin/heroku +5 -0
- data/spec/support/command_helpers.rb +17 -0
- data/spec/support/command_interceptor.rb +33 -0
- data/spec/support/random.rb +3 -0
- data/spec/support/reset.rb +13 -0
- metadata +88 -44
- data/features/rails.feature +0 -97
- data/features/step_definitions/bundler_steps.rb +0 -7
- data/features/step_definitions/common_steps.rb +0 -19
- data/features/step_definitions/rails_steps.rb +0 -12
- data/features/support/aruba.rb +0 -12
- data/features/support/env.rb +0 -8
- data/lib/figaro/railtie.rb +0 -16
- data/lib/figaro/tasks.rb +0 -28
- data/spec/figaro/tasks_spec.rb +0 -71
- data/spec/support/rake.rb +0 -11
data/features/rails.feature
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
Feature: Rails
|
2
|
-
Background:
|
3
|
-
Given a new Rails app
|
4
|
-
And I add figaro as a dependency
|
5
|
-
And I bundle
|
6
|
-
And I create "lib/tasks/hello.rake" with:
|
7
|
-
"""
|
8
|
-
task :hello => :environment do
|
9
|
-
puts ["Hello", ENV["HELLO"]].reject(&:blank?).join(", ") << "!"
|
10
|
-
end
|
11
|
-
|
12
|
-
task :greet => :environment do
|
13
|
-
puts ([Figaro.env.greeting] * 3).join(", ") << "!"
|
14
|
-
end
|
15
|
-
"""
|
16
|
-
|
17
|
-
Scenario: Has no application.yml
|
18
|
-
When I run "rake hello"
|
19
|
-
Then the output should be "Hello!"
|
20
|
-
|
21
|
-
Scenario: Has blank application.yml
|
22
|
-
Given I create "config/application.yml" with:
|
23
|
-
"""
|
24
|
-
"""
|
25
|
-
When I run "rake hello"
|
26
|
-
Then the output should be "Hello!"
|
27
|
-
|
28
|
-
Scenario: Has commented application.yml
|
29
|
-
Given I create "config/application.yml" with:
|
30
|
-
"""
|
31
|
-
# Comment
|
32
|
-
"""
|
33
|
-
When I run "rake hello"
|
34
|
-
Then the output should be "Hello!"
|
35
|
-
|
36
|
-
Scenario: Has application.yml with RAILS_ENV set
|
37
|
-
Given I create "config/application.yml" with:
|
38
|
-
"""
|
39
|
-
HELLO: world
|
40
|
-
development:
|
41
|
-
HELLO: developers
|
42
|
-
production:
|
43
|
-
HELLO: users
|
44
|
-
"""
|
45
|
-
When I run "rake hello RAILS_ENV=test"
|
46
|
-
Then the output should be "Hello, world!"
|
47
|
-
When I run "rake hello RAILS_ENV=development"
|
48
|
-
Then the output should be "Hello, developers!"
|
49
|
-
When I run "rake hello RAILS_ENV=production"
|
50
|
-
Then the output should be "Hello, users!"
|
51
|
-
|
52
|
-
Scenario: Generator creates and ignores application.yml file
|
53
|
-
When I run "rails generate figaro:install"
|
54
|
-
Then "config/application.yml" should exist
|
55
|
-
And ".gitignore" should contain "/config/application.yml"
|
56
|
-
|
57
|
-
Scenario: Generator only creates application.yml if not using Git
|
58
|
-
Given I run "rm .gitignore"
|
59
|
-
When I run "rails generate figaro:install"
|
60
|
-
Then "config/application.yml" should exist
|
61
|
-
But ".gitignore" should not exist
|
62
|
-
|
63
|
-
Scenario: Includes Heroku Rake task
|
64
|
-
When I run "rake --tasks figaro:heroku"
|
65
|
-
Then the output should be "rake figaro:heroku[app] # Configure Heroku according to application.yml"
|
66
|
-
|
67
|
-
Scenario: Accessing values through the Figaro.env proxy
|
68
|
-
Given I create "config/application.yml" with:
|
69
|
-
"""
|
70
|
-
GREETING: Figaro
|
71
|
-
"""
|
72
|
-
When I run "rake greet"
|
73
|
-
Then the output should be "Figaro, Figaro, Figaro!"
|
74
|
-
|
75
|
-
Scenario: Overriding values in application.yml
|
76
|
-
Given I create "config/application.yml" with:
|
77
|
-
"""
|
78
|
-
GREETING: Figaro
|
79
|
-
"""
|
80
|
-
When I run "rake greet GREETING=Ho"
|
81
|
-
Then the output should be "Ho, Ho, Ho!"
|
82
|
-
|
83
|
-
Scenario: Nullifying values in application.yml
|
84
|
-
Given I create "config/application.yml" with:
|
85
|
-
"""
|
86
|
-
HELLO: world
|
87
|
-
"""
|
88
|
-
When I run "rake hello HELLO="
|
89
|
-
Then the output should be "Hello!"
|
90
|
-
|
91
|
-
Scenario: Using ERB in application.yml
|
92
|
-
Given I create "config/application.yml" with:
|
93
|
-
"""
|
94
|
-
GREETING: <%= "Yo" %>
|
95
|
-
"""
|
96
|
-
When I run "rake greet"
|
97
|
-
Then the output should be "Yo, Yo, Yo!"
|
@@ -1,19 +0,0 @@
|
|
1
|
-
When /^I create "([^"]+)" with:$/ do |path, content|
|
2
|
-
write_file(path, content)
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I run "([^"]+)"$/ do |command|
|
6
|
-
run_simple(command)
|
7
|
-
end
|
8
|
-
|
9
|
-
Then /^the output should be "([^"]*)"$/ do |output|
|
10
|
-
assert_exact_output(output, output_from(@commands.last).strip)
|
11
|
-
end
|
12
|
-
|
13
|
-
Then /^"([^"]+)" should ?(not)? exist$/ do |path, negative|
|
14
|
-
check_file_presence([path], !negative)
|
15
|
-
end
|
16
|
-
|
17
|
-
Then /^"([^"]+)" should contain "([^"]*)"$/ do |path, content|
|
18
|
-
check_file_content(path, content, true)
|
19
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
Given "a new Rails app" do
|
2
|
-
in_current_dir { FileUtils.rm_rf("example") }
|
3
|
-
run_simple(<<-CMD)
|
4
|
-
bundle exec rails new example \
|
5
|
-
--skip-bundle \
|
6
|
-
--skip-active-record \
|
7
|
-
--skip-sprockets \
|
8
|
-
--skip-javascript \
|
9
|
-
--skip-test-unit
|
10
|
-
CMD
|
11
|
-
cd("example")
|
12
|
-
end
|
data/features/support/aruba.rb
DELETED
data/features/support/env.rb
DELETED
data/lib/figaro/railtie.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require "rails"
|
2
|
-
require "yaml"
|
3
|
-
|
4
|
-
module Figaro
|
5
|
-
class Railtie < ::Rails::Railtie
|
6
|
-
config.before_configuration do
|
7
|
-
Figaro.env.each do |key, value|
|
8
|
-
ENV[key] = value unless ENV.key?(key)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
rake_tasks do
|
13
|
-
load "figaro/tasks.rake"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/figaro/tasks.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "bundler"
|
2
|
-
|
3
|
-
module Figaro
|
4
|
-
module Tasks
|
5
|
-
class Heroku < Struct.new(:app)
|
6
|
-
def invoke
|
7
|
-
heroku("config:set #{vars}")
|
8
|
-
end
|
9
|
-
|
10
|
-
def vars
|
11
|
-
Figaro.vars(environment)
|
12
|
-
end
|
13
|
-
|
14
|
-
def environment
|
15
|
-
heroku("run 'echo $RAILS_ENV'").chomp[/(\w+)\z/]
|
16
|
-
end
|
17
|
-
|
18
|
-
def heroku(command)
|
19
|
-
with_app = app ? " --app #{app}" : ""
|
20
|
-
`heroku #{command}#{with_app}`
|
21
|
-
end
|
22
|
-
|
23
|
-
def `(command)
|
24
|
-
Bundler.with_clean_env { super }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/spec/figaro/tasks_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Figaro::Tasks
|
4
|
-
describe Heroku do
|
5
|
-
subject(:heroku) { Heroku.new }
|
6
|
-
|
7
|
-
describe "#invoke" do
|
8
|
-
it "configures Heroku" do
|
9
|
-
heroku.stub(:vars => "FOO=bar")
|
10
|
-
|
11
|
-
heroku.should_receive(:heroku).once.with("config:set FOO=bar")
|
12
|
-
|
13
|
-
heroku.invoke
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#vars" do
|
18
|
-
it "returns Figaro's vars for Heroku's environment" do
|
19
|
-
heroku.stub(:environment => "staging")
|
20
|
-
Figaro.stub(:vars).with("staging").and_return("FOO=bar")
|
21
|
-
|
22
|
-
expect(heroku.vars).to eq("FOO=bar")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#environment" do
|
27
|
-
it "returns Heroku's environment" do
|
28
|
-
heroku.stub(:heroku).with("run 'echo $RAILS_ENV'").and_return(<<-OUT)
|
29
|
-
Running `echo $RAILS_ENV` attached to terminal... up, run.1234
|
30
|
-
staging
|
31
|
-
OUT
|
32
|
-
|
33
|
-
expect(heroku.environment).to eq("staging")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#heroku" do
|
38
|
-
it "runs a command on Heroku" do
|
39
|
-
heroku.should_receive(:`).once.with("heroku info")
|
40
|
-
|
41
|
-
heroku.heroku("info")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "runs a command on a specific Heroku app" do
|
45
|
-
heroku = Heroku.new("my-app")
|
46
|
-
|
47
|
-
heroku.should_receive(:`).once.with("heroku info --app my-app")
|
48
|
-
|
49
|
-
heroku.heroku("info")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "figaro:heroku", :rake => true do
|
55
|
-
subject(:heroku) { mock(:heroku) }
|
56
|
-
|
57
|
-
it "configures Heroku" do
|
58
|
-
Figaro::Tasks::Heroku.stub(:new).with(nil).and_return(heroku)
|
59
|
-
heroku.should_receive(:invoke).once
|
60
|
-
|
61
|
-
task.invoke
|
62
|
-
end
|
63
|
-
|
64
|
-
it "configures a specific Heroku app" do
|
65
|
-
Figaro::Tasks::Heroku.stub(:new).with("my-app").and_return(heroku)
|
66
|
-
heroku.should_receive(:invoke).once
|
67
|
-
|
68
|
-
task.invoke("my-app")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/support/rake.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require "rake"
|
2
|
-
|
3
|
-
shared_context "rake", :rake => true do
|
4
|
-
let(:rake) { Rake.application = Rake::Application.new }
|
5
|
-
let(:task) { rake[self.class.description] }
|
6
|
-
|
7
|
-
before do
|
8
|
-
rake.rake_require("lib/figaro/tasks", [ROOT.to_s], [])
|
9
|
-
Rake::Task.define_task(:environment)
|
10
|
-
end
|
11
|
-
end
|