# encoding: utf-8 require 'spec_helper' describe LocalPac::Config do let(:config_file) { create_file('config_.yaml') } context '#initialize' do it 'requires a file name' do LocalPac::Config.new(config_file) end end context '#pid_file' do it 'returns value of config file' do config_file = create_file 'config.yaml', <<-EOS.strip_heredoc --- :pid_file: '/asdf/pid' EOS config = LocalPac::Config.new(config_file) expect(config.pid_file).to eq('/asdf/pid') end it 'returns default value if no config file is available' do config = LocalPac::Config.new(config_file) file = ::File.join(ENV['HOME'], '.local', 'share', 'local_pac', 'run', 'pid') expect(config.pid_file).to eq(file) end end context '#local_storage' do it 'returns value of config file' do config_file = create_file 'config.yaml', <<-EOS.strip_heredoc --- :local_storage: '/asdf/storage.git' EOS config = LocalPac::Config.new(config_file) expect(config.local_storage).to eq('/asdf/storage.git') end it 'returns default value if no config file is available' do config = LocalPac::Config.new(config_file) file = ::File.join(ENV['HOME'], '.local', 'share', 'local_pac', 'data', 'storage.git') expect(config.local_storage).to eq(file) end end context '#access_log' do it 'returns value of config file' do config_file = create_file 'config.yaml', <<-EOS.strip_heredoc --- :access_log: '/asdf/log/access.log' EOS config = LocalPac::Config.new(config_file) expect(config.access_log).to eq('/asdf/log/access.log') end it 'returns default value if no config file is available' do config = LocalPac::Config.new(config_file) file = ::File.join(ENV['HOME'], '.local', 'share', 'local_pac', 'log', 'access.log') expect(config.access_log).to eq(file) end end context 'executable' do it 'returns value of config file' do config_file = create_file 'config.yaml', <<-EOS.strip_heredoc --- :executable: '/asdf/bin/local_pac' EOS config = LocalPac::Config.new(config_file) expect(config.executable).to eq('/asdf/bin/local_pac') end it 'returns default value if no config file is available' do config = LocalPac::Config.new(config_file) file = ::File.expand_path('../../bin/local_pac', __FILE__) expect(config.executable).to eq(file) end end context 'gem_path' do it 'returns value of gem installation path file' do config_file = create_file 'config.yaml', <<-EOS.strip_heredoc --- :gem_path: '/asdf/bin/local_pac' EOS config = LocalPac::Config.new(config_file) expect(config.gem_path).to eq('/asdf/bin/local_pac') end it 'returns default value if no config file is available' do config = LocalPac::Config.new(config_file) expect(config.gem_path).to eq(Gem.path) end end context '#to_s' do it 'outputs a nice config overview' do config = LocalPac::Config.new(config_file) expect(config.to_s).to include ::File.join('.local', 'share', 'local_pac', 'run', 'pid') end end context '#lock' do it 'raises and exception if changed afterward' do config = LocalPac::Config.new(config_file) config.lock expect { config.local_storage = 'asdf' }.to raise_error RuntimeError end end end