Sha256: 0e9cdaf87848e5d6fbd653160de06c19d16250bffd88dcef5f72b58a878c9f04
Contents?: true
Size: 1.76 KB
Versions: 3
Compression:
Stored size: 1.76 KB
Contents
# frozen_string_literal: true require 'spec_helper' require 'ditty/services/settings' describe ::Ditty::Services::Settings do def setup_files settings = File.read('./spec/fixtures/settings.yml') section = File.read('./spec/fixtures/section.yml') allow(File).to receive(:file?).and_return(false) allow(File).to receive(:file?).with('./config/settings.yml').and_return(true) allow(File).to receive(:file?).with('./config/section.yml').and_return(true) allow(File).to receive(:read).with('./config/settings.yml').and_return(settings) allow(File).to receive(:read).with('./config/section.yml').and_return(section) end describe '#[]' do before do setup_files described_class.values = nil end it 'returns the specified values from the global settings' do expect(described_class[:option_a]).to eq 1 end it 'allows access to sectional settings' do expect(described_class[:no_file_section]).to include(section_1: 2, section_2: 'set') end it 'allows using dots to travers' do expect(described_class['nested.option']).to eq 'value' end end describe '#values' do context 'uses the global file' do before do setup_files end it 'to return global settings' do expect(described_class.values).to include(option_a: 1, option_b: 'value') end it 'to return sectional settings' do expect(described_class.values(:no_file_section)).to include(section_1: 2, section_2: 'set') end end context 'uses the sectional file' do before do setup_files end it 'prefers the sectional settings file' do expect(described_class.values(:section)).to include(section_1: 3, section_2: 'section') end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ditty-0.11.1 | spec/ditty/services/settings_spec.rb |
ditty-0.10.2 | spec/ditty/services/settings_spec.rb |
ditty-0.10.1 | spec/ditty/services/settings_spec.rb |