Sha256: c46b1bf6ed8e5d4ff43c03d6f29103548fd7918afe0555a9ba3310529b9021b3

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 Bytes

Contents

require_relative 'spec_helper'
require 'strftime_logger'
require 'fileutils'

describe StrftimeLogger do
  subject { StrftimeLogger.new("#{log_dir}/application.log.%Y%m%d") }
  let(:log_dir)   { "#{File.dirname(__FILE__)}/log" }
  let(:today)     { Time.now.strftime "%Y%m%d"}
  let(:now)       { Time.now.iso8601 }

  before do
    Dir.mkdir(log_dir)
    Timecop.freeze(Time.now)
  end

  after do
    FileUtils.rm_rf log_dir
    Timecop.return
  end

  it :write do
    subject.write("test")
    begin
      raise ArgumentError.new('test')
    rescue => e
      subject.write(e)
    end
    File.open("#{log_dir}/application.log.#{today}") do |f|
      expect(f.gets).to eq "#{now} [INFO] test\n"
      expect(f.gets).to match(/#{Regexp.escape(now)} \[INFO\] ArgumentError test/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strftime_logger-0.0.1 spec/formatter_spec.rb