-
Notifications
You must be signed in to change notification settings - Fork 500
/
environment_spec.rb
56 lines (47 loc) · 1.26 KB
/
environment_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "spec_helper"
describe Dotenv::Environment do
subject { env("OPTION_A=1\nOPTION_B=2") }
describe "initialize" do
it "reads the file" do
expect(subject["OPTION_A"]).to eq("1")
expect(subject["OPTION_B"]).to eq("2")
end
it "fails if file does not exist" do
expect do
Dotenv::Environment.new(".does_not_exists")
end.to raise_error(Errno::ENOENT)
end
end
describe "apply" do
it "sets variables in ENV" do
subject.apply
expect(ENV["OPTION_A"]).to eq("1")
end
it "does not overwrite defined variables" do
ENV["OPTION_A"] = "predefined"
subject.apply
expect(ENV["OPTION_A"]).to eq("predefined")
end
context "with overwrite: true" do
subject { env("OPTION_A=1\nOPTION_B=2", overwrite: true) }
it "sets variables in the ENV" do
subject.apply
expect(ENV["OPTION_A"]).to eq("1")
end
it "overwrites defined variables" do
ENV["OPTION_A"] = "predefined"
subject.apply
expect(ENV["OPTION_A"]).to eq("1")
end
end
end
require "tempfile"
def env(text, ...)
file = Tempfile.new("dotenv")
file.write text
file.close
env = Dotenv::Environment.new(file.path, ...)
file.unlink
env
end
end