# encoding: utf-8 require 'spec_helper' require 'fedux_org_stdlib/directory_finder' RSpec.describe DirectoryFinder do context '#preferred_configuration_directory' 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(DirectoryFinder) do def _class_name 'TestDirectory' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.preferred_configuration_directory).to eq File.expand_path('~/.config/my_application/test') end end it 'works with nested module names' do with_env 'HOME' => absolute_path('.') do config_klass = Class.new(DirectoryFinder) do def _class_name 'TestDirectory' end def _module_name 'MyApplication::MySub' end end config = config_klass.new expect(config.preferred_configuration_directory).to eq File.expand_path('~/.config/my_application/my_sub/test') end end end context 'config files' do it 'looks at ~/.test.yaml' do with_env 'HOME' => absolute_path('.') do create_dir '.test' config_klass = Class.new(DirectoryFinder) do def _class_name 'TestDirectory' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.directory).to eq absolute_path('.test') end end it 'looks at ~/.config/my_application/test.yaml' do with_env 'HOME' => absolute_path('.') do create_dir '.config/my_application/test' config_klass = Class.new(DirectoryFinder) do def _class_name 'TestDirectory' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.directory).to eq absolute_path('.config/my_application/test') end end it 'looks at ~/.my_application/test.yaml' do with_env 'HOME' => absolute_path('.') do create_dir '.my_application/test' config_klass = Class.new(DirectoryFinder) do def _class_name 'TestDirectory' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.directory).to eq absolute_path('.my_application/test') end end it 'looks at ~/.test' do with_env 'HOME' => absolute_path('.') do create_dir '.test' config_klass = Class.new(DirectoryFinder) do def _class_name 'TestDirectory' end def _module_name 'MyApplication' end end config = config_klass.new expect(config.directory).to eq absolute_path('.test') end end end end