This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
/
config_file_spec.rb
63 lines (55 loc) · 1.84 KB
/
config_file_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
57
58
59
60
61
62
63
require 'backports'
require_relative 'spec_helper'
describe Sinatra::ConfigFile do
def config_file(*args, &block)
mock_app do
register Sinatra::ConfigFile
set :root, File.expand_path('../config_file', __FILE__)
instance_eval(&block) if block
config_file(*args)
end
end
it 'should set options from a simple config_file' do
config_file 'key_value.yml'
settings.foo.should == 'bar'
settings.something.should == 42
end
it 'should create indifferent hashes' do
config_file 'key_value.yml'
settings.nested['a'].should == 1
settings.nested[:a].should == 1
end
it 'should render options in ERB tags' do
config_file 'key_value.yml.erb'
settings.foo.should == "bar"
settings.something.should == 42
settings.nested['a'].should == 1
settings.nested[:a].should == 1
settings.nested['b'].should == 2
settings.nested[:b].should == 2
end
it 'should recognize env specific settings per file' do
config_file 'with_envs.yml'
settings.foo.should == 'test'
end
it 'should recognize env specific settings per setting' do
config_file 'with_nested_envs.yml'
settings.database[:adapter].should == 'sqlite'
end
it 'should not set present values to nil if the current env is missing' do
# first let's check the test is actually working properly
config_file('missing_env.yml') { set :foo => 42, :environment => :production }
settings.foo.should == 10
# now test it
config_file('missing_env.yml') { set :foo => 42, :environment => :test }
settings.foo.should == 42
end
it 'should prioritize settings in latter files' do
# first let's check the test is actually working properly
config_file 'key_value.yml'
settings.foo.should == 'bar'
# now test it
config_file 'key_value_override.yml'
settings.foo.should == 'foo'
end
end