Skip to content

Commit 39a1e4c

Browse files
authored
Merge pull request #64 from bibendi/fix/run-vars
Fix passing env vars through argv
2 parents 0cd67d0 + 36892e9 commit 39a1e4c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/dip/run_vars.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def call(*args)
1717
def initialize(argv, env = ENV)
1818
@argv = argv
1919
@env = env
20-
21-
self.class.env.clear
2220
end
2321

2422
def call
@@ -32,7 +30,7 @@ def populate_env_vars
3230
return if early_envs.empty?
3331

3432
(env.keys - early_envs).each do |key|
35-
next if env_excluded?(key)
33+
next if ignore_var?(key)
3634

3735
self.class.env[key] = env[key]
3836
end
@@ -56,7 +54,7 @@ def early_envs
5654
@early_envs ||= env["DIP_EARLY_ENVS"].to_s.split(",")
5755
end
5856

59-
def env_excluded?(key)
57+
def ignore_var?(key)
6058
key.start_with?("DIP_", "_")
6159
end
6260
end

spec/lib/dip/run_vars_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
end
99

1010
context "when env vars in argv" do
11-
specify do
11+
it "parses them and stores in class var" do
1212
expect(described_class.call(%w(FOO=foo BAR=bar run rspec))).to eq %w(run rspec)
1313
expect(described_class.env).to include("FOO" => "foo", "BAR" => "bar")
1414
end
15+
16+
context "and call multiple times" do
17+
it "doesn't reset previous vars" do
18+
expect(described_class.call(%w(FOO=foo BAR=bar run rspec))).to eq %w(run rspec)
19+
expect(described_class.call(%w(run rspec))).to eq %w(run rspec)
20+
expect(described_class.env).to include("FOO" => "foo", "BAR" => "bar")
21+
end
22+
end
1523
end
1624

1725
context "when early_envs is present" do

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
config.before do
4545
Dip.reset!
46+
Dip::RunVars.env.clear
4647
end
4748

4849
Kernel.srand config.seed

0 commit comments

Comments
 (0)