1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-01 03:49:36 +00:00
Holger Just 99728842aa Pass the raw messages array in the event Hash to the encoder
The encoder is then responsible to format it as it pleases. Commonly,
encoders can use Rackstash::Encoders::Helpers::Message#normalize_message
to create a single combined message string.

If the encoder is not interested in using the message, it can jsut get
rid if it without incuring any overhead.
2017-08-22 00:02:10 +02:00

36 lines
998 B
Ruby

# frozen_string_literal: true
# Copyright 2017 Holger Just
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'spec_helper'
require 'rackstash/encoders/helpers/message'
describe Rackstash::Encoders::Helpers::Message do
let(:helper) { Object.new.extend(described_class) }
let(:event) { {} }
describe '#normalize_message' do
it 'concatenates the message array' do
event['message'] = ["a\n", "b\n"]
expect(helper.normalize_message(event)).to eql 'message' => "a\nb\n"
end
it 'sets message to an empty string if not present' do
event['message'] = nil
expect(helper.normalize_message(event)).to eql 'message' => ''
end
it 'enforces to_s on other messages' do
foo = String.new('foo')
event['message'] = foo
expect(foo).to receive(:to_s).and_call_original
expect(helper.normalize_message(event)).to eql 'message' => 'foo'
end
end
end