daqing_figaro 1.2.1
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.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +6 -0
- data/.rspec +3 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +123 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +345 -0
- data/Rakefile +6 -0
- data/bin/figaro +5 -0
- data/figaro.gemspec +23 -0
- data/gemfiles/rails52.gemfile +11 -0
- data/gemfiles/rails6.gemfile +11 -0
- data/gemfiles/rails60.gemfile +11 -0
- data/lib/figaro/application.rb +91 -0
- data/lib/figaro/cli/heroku_set.rb +33 -0
- data/lib/figaro/cli/install/application.yml +11 -0
- data/lib/figaro/cli/install.rb +32 -0
- data/lib/figaro/cli/task.rb +37 -0
- data/lib/figaro/cli.rb +42 -0
- data/lib/figaro/env.rb +45 -0
- data/lib/figaro/error.rb +17 -0
- data/lib/figaro/rails/application.rb +21 -0
- data/lib/figaro/rails/railtie.rb +9 -0
- data/lib/figaro/rails/tasks.rake +6 -0
- data/lib/figaro/rails.rb +9 -0
- data/lib/figaro.rb +32 -0
- data/spec/figaro/application_spec.rb +262 -0
- data/spec/figaro/cli/heroku_set_spec.rb +67 -0
- data/spec/figaro/cli/install_spec.rb +49 -0
- data/spec/figaro/env_spec.rb +195 -0
- data/spec/figaro/rails/application_spec.rb +41 -0
- data/spec/figaro_spec.rb +99 -0
- data/spec/rails_spec.rb +55 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/aruba.rb +18 -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/reset.rb +13 -0
- metadata +158 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
describe "figaro heroku:set" do
|
2
|
+
before do
|
3
|
+
create_directory("example")
|
4
|
+
cd("example")
|
5
|
+
write_file("config/application.yml", "foo: bar")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "sends Figaro configuration to Heroku" do
|
9
|
+
run_command_and_stop("figaro heroku:set")
|
10
|
+
|
11
|
+
command = commands.last
|
12
|
+
expect(command.name).to eq("heroku")
|
13
|
+
expect(command.args).to eq(["config:set", "foo=bar"])
|
14
|
+
end
|
15
|
+
|
16
|
+
it "respects path" do
|
17
|
+
write_file("env.yml", "foo: bar")
|
18
|
+
|
19
|
+
run_command_and_stop("figaro heroku:set -p env.yml")
|
20
|
+
|
21
|
+
command = commands.last
|
22
|
+
expect(command.name).to eq("heroku")
|
23
|
+
expect(command.args).to eq(["config:set", "foo=bar"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "respects environment" do
|
27
|
+
overwrite_file("config/application.yml", <<-EOF)
|
28
|
+
foo: bar
|
29
|
+
test:
|
30
|
+
foo: baz
|
31
|
+
EOF
|
32
|
+
|
33
|
+
run_command_and_stop("figaro heroku:set -e test")
|
34
|
+
|
35
|
+
command = commands.last
|
36
|
+
expect(command.name).to eq("heroku")
|
37
|
+
expect(command.args).to eq(["config:set", "foo=baz"])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "targets a specific Heroku app" do
|
41
|
+
run_command_and_stop("figaro heroku:set -a foo-bar-app")
|
42
|
+
|
43
|
+
command = commands.last
|
44
|
+
expect(command.name).to eq("heroku")
|
45
|
+
expect(command.args.shift).to eq("config:set")
|
46
|
+
expect(command.args).to match_array(["foo=bar", "--app=foo-bar-app"])
|
47
|
+
end
|
48
|
+
|
49
|
+
it "targets a specific Heroku git remote" do
|
50
|
+
run_command_and_stop("figaro heroku:set -r production")
|
51
|
+
|
52
|
+
command = commands.last
|
53
|
+
expect(command.name).to eq("heroku")
|
54
|
+
expect(command.args.shift).to eq("config:set")
|
55
|
+
expect(command.args).to match_array(["foo=bar", "--remote=production"])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "handles values with special characters" do
|
59
|
+
overwrite_file("config/application.yml", "foo: bar baz")
|
60
|
+
|
61
|
+
run_command_and_stop("figaro heroku:set")
|
62
|
+
|
63
|
+
command = commands.last
|
64
|
+
expect(command.name).to eq("heroku")
|
65
|
+
expect(command.args).to eq(["config:set", "foo=bar baz"])
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe "figaro install" do
|
2
|
+
before do
|
3
|
+
create_directory("example")
|
4
|
+
cd("example")
|
5
|
+
end
|
6
|
+
|
7
|
+
it "creates a configuration file" do
|
8
|
+
run_command_and_stop("figaro install")
|
9
|
+
|
10
|
+
expect("config/application.yml").to be_an_existing_file
|
11
|
+
end
|
12
|
+
|
13
|
+
it "respects path" do
|
14
|
+
run_command_and_stop("figaro install -p env.yml")
|
15
|
+
|
16
|
+
expect("env.yml").to be_an_existing_file
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with a .gitignore file" do
|
20
|
+
before do
|
21
|
+
write_file(".gitignore", <<-EOF)
|
22
|
+
/foo
|
23
|
+
/bar
|
24
|
+
EOF
|
25
|
+
end
|
26
|
+
|
27
|
+
it "Git-ignores the configuration file if applicable" do
|
28
|
+
run_command_and_stop("figaro install")
|
29
|
+
|
30
|
+
expect(".gitignore").to have_file_content(%r(^/foo$))
|
31
|
+
expect(".gitignore").to have_file_content(%r(^/bar$))
|
32
|
+
expect(".gitignore").to have_file_content(%r(^/config/application\.yml$))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "respects path" do
|
36
|
+
run_command_and_stop("figaro install -p env.yml")
|
37
|
+
|
38
|
+
expect(".gitignore").to have_file_content(%r(^/env\.yml$))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "without a .gitignore file" do
|
43
|
+
it "doesn't generate a new .gitignore file" do
|
44
|
+
run_command_and_stop("figaro install")
|
45
|
+
|
46
|
+
expect(".gitignore").not_to be_an_existing_file
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
describe Figaro::ENV do
|
2
|
+
subject(:env) { Figaro::ENV }
|
3
|
+
|
4
|
+
before do
|
5
|
+
::ENV["HELLO"] = "world"
|
6
|
+
::ENV["foo"] = "bar"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#method_missing" do
|
10
|
+
context "plain methods" do
|
11
|
+
it "makes ENV values accessible as lowercase methods" do
|
12
|
+
expect(env.hello).to eq("world")
|
13
|
+
expect(env.foo).to eq("bar")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "makes ENV values accessible as uppercase methods" do
|
17
|
+
expect(env.HELLO).to eq("world")
|
18
|
+
expect(env.FOO).to eq("bar")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "makes ENV values accessible as mixed-case methods" do
|
22
|
+
expect(env.Hello).to eq("world")
|
23
|
+
expect(env.fOO).to eq("bar")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns nil if no ENV key matches" do
|
27
|
+
expect(env.goodbye).to eq(nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "respects a stubbed plain method" do
|
31
|
+
allow(env).to receive(:bar) { "baz" }
|
32
|
+
expect(env.bar).to eq("baz")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "bang methods" do
|
37
|
+
it "makes ENV values accessible as lowercase methods" do
|
38
|
+
expect(env.hello!).to eq("world")
|
39
|
+
expect(env.foo!).to eq("bar")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "makes ENV values accessible as uppercase methods" do
|
43
|
+
expect(env.HELLO!).to eq("world")
|
44
|
+
expect(env.FOO!).to eq("bar")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "makes ENV values accessible as mixed-case methods" do
|
48
|
+
expect(env.Hello!).to eq("world")
|
49
|
+
expect(env.fOO!).to eq("bar")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises an error if no ENV key matches" do
|
53
|
+
expect { env.goodbye! }.to raise_error(Figaro::MissingKey)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "respects a stubbed plain method" do
|
57
|
+
allow(env).to receive(:bar) { "baz" }
|
58
|
+
expect { expect(env.bar!).to eq("baz") }.not_to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "boolean methods" do
|
63
|
+
it "returns true for accessible, lowercase methods" do
|
64
|
+
expect(env.hello?).to eq(true)
|
65
|
+
expect(env.foo?).to eq(true)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns true for accessible, uppercase methods" do
|
69
|
+
expect(env.HELLO?).to eq(true)
|
70
|
+
expect(env.FOO?).to eq(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns true for accessible, mixed-case methods" do
|
74
|
+
expect(env.Hello?).to eq(true)
|
75
|
+
expect(env.fOO?).to eq(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns false if no ENV key matches" do
|
79
|
+
expect(env.goodbye?).to eq(false)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "respects a stubbed plain method" do
|
83
|
+
allow(env).to receive(:bar) { "baz" }
|
84
|
+
expect(env.bar?).to eq(true)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "setter methods" do
|
89
|
+
it "raises an error for accessible, lowercase methods" do
|
90
|
+
expect { env.hello = "world" }.to raise_error(NoMethodError)
|
91
|
+
expect { env.foo = "bar" }.to raise_error(NoMethodError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "raises an error for accessible, uppercase methods" do
|
95
|
+
expect { env.HELLO = "world" }.to raise_error(NoMethodError)
|
96
|
+
expect { env.FOO = "bar" }.to raise_error(NoMethodError)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "raises an error for accessible, mixed-case methods" do
|
100
|
+
expect { env.Hello = "world" }.to raise_error(NoMethodError)
|
101
|
+
expect { env.fOO = "bar" }.to raise_error(NoMethodError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "raises an error if no ENV key matches" do
|
105
|
+
expect { env.goodbye = "world" }.to raise_error(NoMethodError)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#respond_to?" do
|
111
|
+
context "plain methods" do
|
112
|
+
it "returns true for accessible, lowercase methods" do
|
113
|
+
expect(env.respond_to?(:hello)).to eq(true)
|
114
|
+
expect(env.respond_to?(:foo)).to eq(true)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns true for accessible uppercase methods" do
|
118
|
+
expect(env.respond_to?(:HELLO)).to eq(true)
|
119
|
+
expect(env.respond_to?(:FOO)).to eq(true)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "returns true for accessible mixed-case methods" do
|
123
|
+
expect(env.respond_to?(:Hello)).to eq(true)
|
124
|
+
expect(env.respond_to?(:fOO)).to eq(true)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns true if no ENV key matches" do
|
128
|
+
expect(env.respond_to?(:baz)).to eq(true)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "bang methods" do
|
133
|
+
it "returns true for accessible, lowercase methods" do
|
134
|
+
expect(env.respond_to?(:hello!)).to eq(true)
|
135
|
+
expect(env.respond_to?(:foo!)).to eq(true)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "returns true for accessible uppercase methods" do
|
139
|
+
expect(env.respond_to?(:HELLO!)).to eq(true)
|
140
|
+
expect(env.respond_to?(:FOO!)).to eq(true)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "returns true for accessible mixed-case methods" do
|
144
|
+
expect(env.respond_to?(:Hello!)).to eq(true)
|
145
|
+
expect(env.respond_to?(:fOO!)).to eq(true)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "returns false if no ENV key matches" do
|
149
|
+
expect(env.respond_to?(:baz!)).to eq(false)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "boolean methods" do
|
154
|
+
it "returns true for accessible, lowercase methods" do
|
155
|
+
expect(env.respond_to?(:hello?)).to eq(true)
|
156
|
+
expect(env.respond_to?(:foo?)).to eq(true)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns true for accessible uppercase methods" do
|
160
|
+
expect(env.respond_to?(:HELLO?)).to eq(true)
|
161
|
+
expect(env.respond_to?(:FOO?)).to eq(true)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "returns true for accessible mixed-case methods" do
|
165
|
+
expect(env.respond_to?(:Hello?)).to eq(true)
|
166
|
+
expect(env.respond_to?(:fOO?)).to eq(true)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "returns true if no ENV key matches" do
|
170
|
+
expect(env.respond_to?(:baz?)).to eq(true)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "setter methods" do
|
175
|
+
it "returns false for accessible, lowercase methods" do
|
176
|
+
expect(env.respond_to?(:hello=)).to eq(false)
|
177
|
+
expect(env.respond_to?(:foo=)).to eq(false)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "returns false for accessible uppercase methods" do
|
181
|
+
expect(env.respond_to?(:HELLO=)).to eq(false)
|
182
|
+
expect(env.respond_to?(:FOO=)).to eq(false)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "returns false for accessible mixed-case methods" do
|
186
|
+
expect(env.respond_to?(:Hello=)).to eq(false)
|
187
|
+
expect(env.respond_to?(:fOO=)).to eq(false)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "returns false if no ENV key matches" do
|
191
|
+
expect(env.respond_to?(:baz=)).to eq(false)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Figaro
|
2
|
+
module Rails
|
3
|
+
describe Application do
|
4
|
+
describe "#default_path" do
|
5
|
+
let!(:application) { Application.new }
|
6
|
+
|
7
|
+
it "defaults to config/application.yml in Rails.root" do
|
8
|
+
allow(::Rails).to receive(:root) { Pathname.new("/path/to/app") }
|
9
|
+
|
10
|
+
expect {
|
11
|
+
allow(::Rails).to receive(:root) { Pathname.new("/app") }
|
12
|
+
}.to change {
|
13
|
+
application.send(:default_path).to_s
|
14
|
+
}.from("/path/to/app/config/application.yml").to("/app/config/application.yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raises an error when Rails.root isn't set yet" do
|
18
|
+
allow(::Rails).to receive(:root) { nil }
|
19
|
+
|
20
|
+
expect {
|
21
|
+
application.send(:default_path)
|
22
|
+
}.to raise_error(RailsNotInitialized)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#default_environment" do
|
27
|
+
let!(:application) { Application.new }
|
28
|
+
|
29
|
+
it "defaults to Rails.env" do
|
30
|
+
allow(::Rails).to receive(:env) { "development" }
|
31
|
+
|
32
|
+
expect {
|
33
|
+
allow(::Rails).to receive(:env) { "test" }
|
34
|
+
}.to change {
|
35
|
+
application.send(:default_environment).to_s
|
36
|
+
}.from("development").to("test")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/figaro_spec.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
describe Figaro do
|
2
|
+
describe ".env" do
|
3
|
+
it "falls through to Figaro::ENV" do
|
4
|
+
expect(Figaro.env).to eq(Figaro::ENV)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".adapter" do
|
9
|
+
let(:adapter) { double(:adapter) }
|
10
|
+
|
11
|
+
it "defaults to the generic application adapter" do
|
12
|
+
expect(Figaro.adapter).to eq(Figaro::Application)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is configurable" do
|
16
|
+
expect {
|
17
|
+
Figaro.adapter = adapter
|
18
|
+
}.to change {
|
19
|
+
Figaro.adapter
|
20
|
+
}.from(Figaro::Application).to(adapter)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".application" do
|
25
|
+
let(:adapter) { double(:adapter) }
|
26
|
+
let(:application) { double(:application) }
|
27
|
+
let(:custom_application) { double(:custom_application) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(Figaro).to receive(:adapter) { adapter }
|
31
|
+
allow(adapter).to receive(:new).with(no_args) { application }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "defaults to a new adapter application" do
|
35
|
+
expect(Figaro.application).to eq(application)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "is configurable" do
|
39
|
+
expect {
|
40
|
+
Figaro.application = custom_application
|
41
|
+
}.to change {
|
42
|
+
Figaro.application
|
43
|
+
}.from(application).to(custom_application)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".load" do
|
48
|
+
let(:application) { double(:application) }
|
49
|
+
|
50
|
+
before do
|
51
|
+
allow(Figaro).to receive(:application) { application }
|
52
|
+
end
|
53
|
+
|
54
|
+
it "loads the application configuration" do
|
55
|
+
expect(application).to receive(:load).once.with(no_args)
|
56
|
+
|
57
|
+
Figaro.load
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".require_keys" do
|
62
|
+
before do
|
63
|
+
::ENV["foo"] = "bar"
|
64
|
+
::ENV["hello"] = "world"
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when no keys are missing" do
|
68
|
+
it "does nothing" do
|
69
|
+
expect {
|
70
|
+
Figaro.require_keys("foo", "hello")
|
71
|
+
}.not_to raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
it "accepts an array" do
|
75
|
+
expect {
|
76
|
+
Figaro.require_keys(["foo", "hello"])
|
77
|
+
}.not_to raise_error
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when keys are missing" do
|
82
|
+
it "raises an error for the missing keys" do
|
83
|
+
expect {
|
84
|
+
Figaro.require_keys("foo", "goodbye", "baz")
|
85
|
+
}.to raise_error(Figaro::MissingKeys) { |error|
|
86
|
+
expect(error.message).not_to include("foo")
|
87
|
+
expect(error.message).to include("goodbye")
|
88
|
+
expect(error.message).to include("baz")
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
it "accepts an array" do
|
93
|
+
expect {
|
94
|
+
Figaro.require_keys(["foo", "goodbye", "baz"])
|
95
|
+
}.to raise_error(Figaro::MissingKeys)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/rails_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
describe Figaro::Rails do
|
2
|
+
before do
|
3
|
+
run_command_and_stop(<<-CMD)
|
4
|
+
rails new example \
|
5
|
+
--skip-gemfile \
|
6
|
+
--skip-git \
|
7
|
+
--skip-keeps \
|
8
|
+
--skip-sprockets \
|
9
|
+
--skip-spring \
|
10
|
+
--skip-listen \
|
11
|
+
--skip-javascript \
|
12
|
+
--skip-turbolinks \
|
13
|
+
--skip-test \
|
14
|
+
--skip-bootsnap \
|
15
|
+
--no-rc \
|
16
|
+
--skip-bundle \
|
17
|
+
--skip-webpack-install
|
18
|
+
CMD
|
19
|
+
cd("example")
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "initialization" do
|
23
|
+
before do
|
24
|
+
write_file("config/application.yml", "foo: bar")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "loads application.yml" do
|
28
|
+
run_command_and_stop("rails runner 'puts Figaro.env.foo'")
|
29
|
+
|
30
|
+
expect(all_stdout).to include("bar")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "happens before database initialization" do
|
34
|
+
write_file("config/database.yml", <<-EOF)
|
35
|
+
development:
|
36
|
+
adapter: sqlite3
|
37
|
+
database: db/<%= ENV["foo"] %>.sqlite3
|
38
|
+
EOF
|
39
|
+
|
40
|
+
run_command_and_stop("rake db:migrate")
|
41
|
+
|
42
|
+
expect("db/bar.sqlite3").to be_an_existing_file
|
43
|
+
end
|
44
|
+
|
45
|
+
it "happens before application configuration" do
|
46
|
+
insert_into_file_after("config/application.rb", /< Rails::Application$/, <<-EOL)
|
47
|
+
config.foo = ENV["foo"]
|
48
|
+
EOL
|
49
|
+
|
50
|
+
run_command_and_stop("rails runner 'puts Rails.application.config.foo'")
|
51
|
+
|
52
|
+
expect(all_stdout).to include("bar")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "aruba/api"
|
2
|
+
|
3
|
+
module ArubaHelpers
|
4
|
+
def insert_into_file_after(file, pattern, addition)
|
5
|
+
content = cd(".") { 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
|
+
setup_aruba
|
17
|
+
end
|
18
|
+
end
|
@@ -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,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
|