Sha256: 7c578c8e204ce4f4ea3955155c006f4800f32929303c377a0cbde8e745e88de3

Contents?: true

Size: 1.43 KB

Versions: 85

Compression:

Stored size: 1.43 KB

Contents

#frozen_string_literal: true

package_require('ree_logger/appenders/file_appender')

RSpec.describe ReeLogger::FileAppender do
  link :is_blank, from: :ree_object

  let(:file_appender) { described_class }

  let(:log_event) {
    ReeLogger::LogEvent.new(
      :info,
      "Some message",
      nil,
      {}
    )
  }

  let(:log_file_path) { ENV['LOG_FILE_PATH'] }

  before(:all) do
    tmp_file_log = ENV['LOG_FILE_PATH']

    if !is_blank(tmp_file_log)
      File.open(tmp_file_log, 'w') {|file| file.truncate(0) }
    end
  end

  after(:all) do
    tmp_file_log = ENV['LOG_FILE_PATH']

    if !is_blank(tmp_file_log)
      File.open(tmp_file_log, 'w') {|file| file.truncate(0) }
    end
  end

  let(:custom_formatter) {
    Class.new(ReeLogger::Formatter) do
      def format(event, progname = nil)
        event.message.upcase
      end
    end
  }

  it "with default formatter" do
    appender = file_appender.new(
      :info,
      nil,
      log_file_path,
      auto_flush: true
    )

    expect(appender).to respond_to(:append)

    appender.append(log_event)
    expect(File.read(log_file_path)).to match(log_event.message)
  end

  it "with custom formatter" do
    appender = file_appender.new(
      :info,
      custom_formatter.new,
      log_file_path,
      auto_flush: true
    )

    expect(appender).to respond_to(:append)

    appender.append(log_event)
    expect(File.read(log_file_path)).to match(log_event.message.upcase)
  end
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_logger/spec/ree_logger/appenders/file_appender_spec.rb