dotenv 0.10.0 → 2.8.0

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.
@@ -1,175 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Dotenv::Environment do
4
- subject { env("OPTION_A=1\nOPTION_B=2") }
5
-
6
- describe 'initialize' do
7
- it 'reads the file' do
8
- expect(subject['OPTION_A']).to eq('1')
9
- expect(subject['OPTION_B']).to eq('2')
10
- end
11
-
12
- it 'fails if file does not exist' do
13
- expect {
14
- Dotenv::Environment.new('.does_not_exists')
15
- }.to raise_error(Errno::ENOENT)
16
- end
17
- end
18
-
19
- describe 'apply' do
20
- it 'sets variables in ENV' do
21
- subject.apply
22
- expect(ENV['OPTION_A']).to eq('1')
23
- end
24
-
25
- it 'does not override defined variables' do
26
- ENV['OPTION_A'] = 'predefined'
27
- subject.apply
28
- expect(ENV['OPTION_A']).to eq('predefined')
29
- end
30
- end
31
-
32
- describe 'apply!' do
33
- it 'sets variables in the ENV' do
34
- subject.apply
35
- expect(ENV['OPTION_A']).to eq('1')
36
- end
37
-
38
- it 'overrides defined variables' do
39
- ENV['OPTION_A'] = 'predefined'
40
- subject.apply!
41
- expect(ENV['OPTION_A']).to eq('1')
42
- end
43
- end
44
-
45
- it 'parses unquoted values' do
46
- expect(env('FOO=bar')).to eql('FOO' => 'bar')
47
- end
48
-
49
- it 'parses values with spaces around equal sign' do
50
- expect(env("FOO =bar")).to eql('FOO' => 'bar')
51
- expect(env("FOO= bar")).to eql('FOO' => 'bar')
52
- end
53
-
54
- it 'parses double quoted values' do
55
- expect(env('FOO="bar"')).to eql('FOO' => 'bar')
56
- end
57
-
58
- it 'parses single quoted values' do
59
- expect(env("FOO='bar'")).to eql('FOO' => 'bar')
60
- end
61
-
62
- it 'parses escaped double quotes' do
63
- expect(env('FOO="escaped\"bar"')).to eql('FOO' => 'escaped"bar')
64
- end
65
-
66
- it 'parses empty values' do
67
- expect(env('FOO=')).to eql('FOO' => '')
68
- end
69
-
70
- it 'expands variables found in values' do
71
- expect(env("FOO=test\nBAR=$FOO")).to eql('FOO' => 'test', 'BAR' => 'test')
72
- end
73
-
74
- it 'parses variables wrapped in brackets' do
75
- expect(env("FOO=test\nBAR=${FOO}bar")).to eql('FOO' => 'test', 'BAR' => 'testbar')
76
- end
77
-
78
- it 'reads variables from ENV when expanding if not found in local env' do
79
- ENV['FOO'] = 'test'
80
- expect(env('BAR=$FOO')).to eql('BAR' => 'test')
81
- end
82
-
83
- it 'expands undefined variables to an empty string' do
84
- expect(env('BAR=$FOO')).to eql('BAR' => '')
85
- end
86
-
87
- it 'expands variables in quoted strings' do
88
- expect(env("FOO=test\nBAR='quote $FOO'")).to eql('FOO' => 'test', 'BAR' => 'quote test')
89
- end
90
-
91
- it 'does not expand escaped variables' do
92
- expect(env('FOO="foo\$BAR"')).to eql('FOO' => 'foo$BAR')
93
- expect(env('FOO="foo\${BAR}"')).to eql('FOO' => 'foo${BAR}')
94
- end
95
-
96
- it 'parses yaml style options' do
97
- expect(env('OPTION_A: 1')).to eql('OPTION_A' => '1')
98
- end
99
-
100
- it 'parses export keyword' do
101
- expect(env('export OPTION_A=2')).to eql('OPTION_A' => '2')
102
- end
103
-
104
- it 'expands newlines in quoted strings' do
105
- expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")
106
- end
107
-
108
- it 'parses variables with "." in the name' do
109
- expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar')
110
- end
111
-
112
- it 'strips unquoted values' do
113
- expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar '
114
- end
115
-
116
- it 'throws an error if line format is incorrect' do
117
- expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
118
- end
119
-
120
- it 'ignores empty lines' do
121
- expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz')
122
- end
123
-
124
- it 'ignores inline comments' do
125
- expect(env("foo=bar # this is foo")).to eql('foo' => 'bar')
126
- end
127
-
128
- it 'allows # in quoted value' do
129
- expect(env('foo="bar#baz" # comment')).to eql('foo' => 'bar#baz')
130
- end
131
-
132
- it 'ignores comment lines' do
133
- expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar')
134
- end
135
-
136
- it 'parses # in quoted values' do
137
- expect(env('foo="ba#r"')).to eql('foo' => 'ba#r')
138
- expect(env("foo='ba#r'")).to eql('foo' => 'ba#r')
139
- end
140
-
141
- if RUBY_VERSION > '1.8.7'
142
- it 'parses shell commands interpolated in $()' do
143
- expect(env('ruby_v=$(ruby -v)')).to eql('ruby_v' => RUBY_DESCRIPTION)
144
- end
145
-
146
- it 'allows balanced parentheses within interpolated shell commands' do
147
- expect(env('ruby_v=$(echo "$(echo "$(echo "$(ruby -v)")")")')).to eql('ruby_v' => RUBY_DESCRIPTION)
148
- end
149
-
150
- it "doesn't interpolate shell commands when escape says not to" do
151
- expect(env('ruby_v=escaped-\$(ruby -v)')).to eql('ruby_v' => 'escaped-$(ruby -v)')
152
- end
153
-
154
- it 'is not thrown off by quotes in interpolated shell commands' do
155
- expect(env('interp=$(echo "Quotes won\'t be a problem")')['interp']).to eql("Quotes won't be a problem")
156
- end
157
-
158
- # This functionality is not supported on JRuby or Rubinius
159
- if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby') && !defined?(Rubinius)
160
- it 'substitutes shell variables within interpolated shell commands' do
161
- expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))['interp']).to eql("VAR1 is var1")
162
- end
163
- end
164
- end
165
-
166
- require 'tempfile'
167
- def env(text)
168
- file = Tempfile.new('dotenv')
169
- file.write text
170
- file.close
171
- env = Dotenv::Environment.new(file.path)
172
- file.unlink
173
- env
174
- end
175
- end
data/spec/dotenv_spec.rb DELETED
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Dotenv do
4
- shared_examples 'load' do
5
- context 'with no args' do
6
- let(:env_files) { [] }
7
-
8
- it 'defaults to .env' do
9
- expect(Dotenv::Environment).to receive(:new).with(expand('.env')).
10
- and_return(double(:apply => {}))
11
- subject
12
- end
13
- end
14
-
15
- context 'with a tilde path' do
16
- let(:env_files) { ['~/.env'] }
17
-
18
- it 'expands the path' do
19
- expected = expand("~/.env")
20
- allow(File).to receive(:exists?){ |arg| arg == expected }
21
- expect(Dotenv::Environment).to receive(:new).with(expected).
22
- and_return(double(:apply => {}))
23
- subject
24
- end
25
- end
26
-
27
- context 'with multiple files' do
28
- let(:env_files) { ['.env', fixture_path('plain.env')] }
29
-
30
- let(:expected) do
31
- { 'OPTION_A' => '1',
32
- 'OPTION_B' => '2',
33
- 'OPTION_C' => '3',
34
- 'OPTION_D' => '4',
35
- 'OPTION_E' => '5',
36
- 'DOTENV' => 'true' }
37
- end
38
-
39
- it 'loads all files' do
40
- subject
41
- expected.each do |key, value|
42
- expect(ENV[key]).to eq(value)
43
- end
44
- end
45
-
46
- it 'returns hash of loaded environments' do
47
- expect(subject).to eq(expected)
48
- end
49
- end
50
- end
51
-
52
- describe 'load' do
53
- subject { Dotenv.load(*env_files) }
54
-
55
- it_behaves_like 'load'
56
-
57
- context 'when the file does not exist' do
58
- let(:env_files) { ['.env_does_not_exist'] }
59
-
60
- it 'fails silently' do
61
- expect { subject }.not_to raise_error
62
- expect(ENV.keys).to eq(@env_keys)
63
- end
64
- end
65
- end
66
-
67
- describe 'load!' do
68
- subject { Dotenv.load!(*env_files) }
69
-
70
- it_behaves_like 'load'
71
-
72
- context 'when one file exists and one does not' do
73
- let(:env_files) { ['.env', '.env_does_not_exist'] }
74
-
75
- it 'raises an Errno::ENOENT error and does not load any files' do
76
- expect do
77
- expect do
78
- subject
79
- end.to raise_error(Errno::ENOENT)
80
- end.to_not change { ENV.keys }
81
- end
82
- end
83
- end
84
-
85
- describe 'overload' do
86
- it 'overrides any existing ENV variables' do
87
- ENV['OPTION_A'] = 'predefined'
88
- path = fixture_path 'plain.env'
89
-
90
- Dotenv.overload(path)
91
-
92
- expect(ENV['OPTION_A']).to eq('1')
93
- end
94
- end
95
-
96
- def fixture_path(name)
97
- File.join(File.expand_path('../fixtures', __FILE__), name)
98
- end
99
-
100
- def expand(path)
101
- File.expand_path path
102
- end
103
- end
@@ -1,2 +0,0 @@
1
- export OPTION_A=2
2
- export OPTION_B='\n'
@@ -1,5 +0,0 @@
1
- OPTION_A=1
2
- OPTION_B=2
3
- OPTION_C= 3
4
- OPTION_D =4
5
- OPTION_E = 5
@@ -1,8 +0,0 @@
1
- OPTION_A='1'
2
- OPTION_B='2'
3
- OPTION_C=''
4
- OPTION_D='\n'
5
- OPTION_E="1"
6
- OPTION_F="2"
7
- OPTION_G=""
8
- OPTION_H="\n"
@@ -1,4 +0,0 @@
1
- OPTION_A: 1
2
- OPTION_B: '2'
3
- OPTION_C: ''
4
- OPTION_D: '\n'
data/spec/spec_helper.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'dotenv'
2
-
3
- RSpec.configure do |config|
4
- # Restore the state of ENV after each spec
5
- config.before { @env_keys = ENV.keys }
6
- config.after { ENV.delete_if { |k,v| !@env_keys.include?(k) } }
7
- end