mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Ensure that the Formatter freezes the strings in all cases
Previously, the returned String would been frozen only in Rubies understanding the frozen_literals magic comment.
This commit is contained in:
parent
168e62b63c
commit
536bb9a087
@ -23,7 +23,7 @@ module Rackstash
|
||||
# @param msg [String, Exception, #inspect] the log message
|
||||
# @return [String] the formatted message with a final newline character
|
||||
def call(_severity, _time, _progname, msg)
|
||||
"#{msg2str(msg)}\n"
|
||||
"#{msg2str(msg)}\n".freeze
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -13,15 +13,22 @@ describe Rackstash::Formatter do
|
||||
let(:formatter) { described_class.new }
|
||||
|
||||
it 'formats plain strings' do
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', 'Hello')).to eql "Hello\n"
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', 'Hello'))
|
||||
.to eql("Hello\n")
|
||||
.and be_frozen
|
||||
end
|
||||
|
||||
it 'formats stringifiable objects' do
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', 123)).to eql "123\n"
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', 123))
|
||||
.to eql("123\n")
|
||||
.and be_frozen
|
||||
end
|
||||
|
||||
it 'formats Arrays' do
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', [1, 'y'])).to eql "[1, \"y\"]\n"
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', [1, 'y']))
|
||||
.to eql("[1, \"y\"]\n")
|
||||
.and be_frozen
|
||||
|
||||
end
|
||||
|
||||
it 'formats exceptions' do
|
||||
@ -36,15 +43,19 @@ describe Rackstash::Formatter do
|
||||
\\AAn Error \\(StandardError\\)
|
||||
#{Regexp.escape __FILE__}:#{__LINE__ - 7}:in `block .*`
|
||||
EOF
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', exception)).to match checker
|
||||
end
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', exception))
|
||||
.to match(checker)
|
||||
.and be_frozen
|
||||
end
|
||||
|
||||
it 'inspects unknown objects' do
|
||||
object = Object.new
|
||||
inspected = object.inspect
|
||||
|
||||
expect(object).to receive(:inspect).once.and_call_original
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', object)).to eql "#{inspected}\n"
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', object))
|
||||
.to eql("#{inspected}\n")
|
||||
.and be_frozen
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user