spec/dotenv/environment_spec.rb in dotenv-0.7.0 vs spec/dotenv/environment_spec.rb in dotenv-0.8.0
- old
+ new
@@ -28,34 +28,72 @@
expect(ENV['OPTION_A']).to eq('predefined')
end
end
it 'parses unquoted values' do
- expect(env('FOO=bar')).to eql({'FOO' => 'bar'})
+ expect(env('FOO=bar')).to eql('FOO' => 'bar')
end
+ it 'parses values with spaces around equal sign' do
+ expect(env("FOO =bar")).to eql('FOO' => 'bar')
+ expect(env("FOO= bar")).to eql('FOO' => 'bar')
+ end
+
it 'parses double quoted values' do
- expect(env('FOO="bar"')).to eql({'FOO' => 'bar'})
+ expect(env('FOO="bar"')).to eql('FOO' => 'bar')
end
it 'parses single quoted values' do
- expect(env("FOO='bar'")).to eql({'FOO' => 'bar'})
+ expect(env("FOO='bar'")).to eql('FOO' => 'bar')
end
it 'parses escaped double quotes' do
- expect(env('FOO="escaped\"bar"')).to eql({'FOO' => 'escaped"bar'})
+ expect(env('FOO="escaped\"bar"')).to eql('FOO' => 'escaped"bar')
end
it 'parses yaml style options' do
- expect(env("OPTION_A: 1")).to eql('OPTION_A' => '1')
+ expect(env('OPTION_A: 1')).to eql('OPTION_A' => '1')
end
it 'parses export keyword' do
- expect(env("export OPTION_A=2")).to eql('OPTION_A' => '2')
+ expect(env('export OPTION_A=2')).to eql('OPTION_A' => '2')
end
it 'expands newlines in quoted strings' do
- expect(env('FOO="bar\nbaz"')).to eql({"FOO" => "bar\nbaz"})
+ expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")
+ end
+
+ it 'parses varibales with "." in the name' do
+ expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar')
+ end
+
+ it 'strips unquoted values' do
+ expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar '
+ end
+
+ it 'throws an error if line format is incorrect' do
+ expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
+ end
+
+ it 'ignores empty lines' do
+ expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz')
+ end
+
+ it 'ignores inline comments' do
+ expect(env("foo=bar # this is foo")).to eql('foo' => 'bar')
+ end
+
+ it 'allows # in quoted value' do
+ expect(env('foo="bar#baz" # comment')).to eql('foo' => 'bar#baz')
+ end
+
+ it 'ignores comment lines' do
+ expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar')
+ end
+
+ it 'parses # in quoted values' do
+ expect(env('foo="ba#r"')).to eql('foo' => 'ba#r')
+ expect(env("foo='ba#r'")).to eql('foo' => 'ba#r')
end
require 'tempfile'
def env(text)
file = Tempfile.new('dotenv')