improved configuration utility
This commit is contained in:
48
spec/lib/code_ocean/config_spec.rb
Normal file
48
spec/lib/code_ocean/config_spec.rb
Normal file
@ -0,0 +1,48 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe CodeOcean::Config do
|
||||
describe '#read' do
|
||||
let(:content) { {foo: 'bar'} }
|
||||
let(:filename) { :foo }
|
||||
|
||||
context 'with a .yml file' do
|
||||
let(:path) { Rails.root.join('config', "#{filename}.yml") }
|
||||
let(:read) { CodeOcean::Config.new(filename).read }
|
||||
|
||||
context 'when the file is present' do
|
||||
before(:each) { File.write(path, {Rails.env => content}.to_yaml) }
|
||||
after(:each) { FileUtils.rm(path) }
|
||||
|
||||
it 'returns the environment-specific content' do
|
||||
expect(read).to eq(content.with_indifferent_access)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the file is not present' do
|
||||
it 'raises an error' do
|
||||
expect { read }.to raise_error(CodeOcean::Config::Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a .yml.erb file' do
|
||||
let(:path) { Rails.root.join('config', "#{filename}.yml.erb") }
|
||||
let(:read) { CodeOcean::Config.new(filename).read(erb: true) }
|
||||
|
||||
context 'when the file is present' do
|
||||
before(:each) { File.write(path, {Rails.env => content}.to_yaml) }
|
||||
after(:each) { FileUtils.rm(path) }
|
||||
|
||||
it 'returns the environment-specific content' do
|
||||
expect(read).to eq(content.with_indifferent_access)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the file is not present' do
|
||||
it 'raises an error' do
|
||||
expect { read }.to raise_error(CodeOcean::Config::Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user