# encoding: utf-8 require 'spec_helper' require 'fedux_org_stdlib/file_finder' RSpec.describe FileFinder do context '#preferred_configuration_file' do it 'has a default configuration file which is the preferred place to store the configuration' do with_env 'HOME' => absolute_path('.') do config_klass = Class.new(FileFinder) do def _class_name 'TestFile' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.preferred_configuration_file).to eq File.expand_path('~/.config/my_application/test.yaml') end end it 'works with nested module names' do with_env 'HOME' => absolute_path('.') do config_klass = Class.new(FileFinder) do def _class_name 'TestFile' end def _module_name 'MyApplication::MySub' end end config = config_klass.new expect(config.preferred_configuration_file).to eq File.expand_path('~/.config/my_application/my_sub/test.yaml') end end end context 'config files' do it 'looks at ~/.test.yaml' do with_env 'HOME' => absolute_path('.') do touch_file '.test.yaml' config_klass = Class.new(FileFinder) do def _class_name 'TestFile' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.file).to eq absolute_path('.test.yaml') end end it 'looks at ~/.config/my_application/test.yaml' do with_env 'HOME' => absolute_path('.') do touch_file '.config/my_application/test.yaml' config_klass = Class.new(FileFinder) do def _class_name 'TestFile' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.file).to eq absolute_path('.config/my_application/test.yaml') end end it 'looks at ~/.my_application/test.yaml' do with_env 'HOME' => absolute_path('.') do touch_file '.my_application/test.yaml' config_klass = Class.new(FileFinder) do def _class_name 'TestFile' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.file).to eq absolute_path('.my_application/test.yaml') end end it 'looks at ~/.testrc' do with_env 'HOME' => absolute_path('.') do touch_file '.testrc' config_klass = Class.new(FileFinder) do def _class_name 'TestFile' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.file).to eq absolute_path('.testrc') end end end end