require 'spec_helper' require 'fileutils' require 'logger' TMP_DIR = REPO_ROOT.join("tmp") FileUtils.rm_rf(TMP_DIR) class Rails def self.configuration self.new end def self.logger Logger.new(STDOUT) end def self.root TMP_DIR end def self.env "test" end def middleware self end def use(mod) end end class ActionController class Base end end class ActiveSupport class TimeWithZone end end require 'td/logger/agent/rails' # NOTE: should be require after Rails goodies mocked describe TreasureData::Logger::Agent::Rails::Config do before(:each) do FileUtils.rm_rf(TMP_DIR) FileUtils.mkdir_p(TMP_DIR) ENV.delete('TREASURE_DATA_API_KEY') ENV.delete('TREASURE_DATA_DB') end context 'init' do it 'load_env' do ENV['TREASURE_DATA_API_KEY'] = 'test1' ENV['TREASURE_DATA_DB'] = 'db1' c = TreasureData::Logger::Agent::Rails::Config.init expect(c.disabled).to eq(false) expect(c.agent_mode?).to eq(false) expect(c.apikey).to eq('test1') expect(c.database).to eq('db1') expect(c.auto_create_table).to eq(true) end it 'load_file' do FileUtils.mkdir_p("#{TMP_DIR}/config") File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f| f.write <