mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-03-25 08:55:47 +00:00
* Add rubocop with a todo list * Run rubocop as part of the CI workflow * Autofix for RuboCop: Layout/ElseAlignment * Regen autogen, removing all claude-scratchpad/* * Autofix RuboCop Layout/EmptyLine * AutoFix RuboCop Style/ZeroLengthPredicate * AutoFix RuboCop Layout/EmptyLinesAroundAccessModifier * AutoFix RuboCop Layout/EmptyLinesAroundMethodBody * AutoFix RuboCop Layout/EmptyLinesAroundBlockBody * AutoFix RuboCop Layout/EmptyLinesAroundClassBody * AutoFix RuboCop Layout/EndAlignment * AutoFix RuboCop Layout/ExtraSpacing * AutoFix RuboCop Layout/FirstHashElementIndentation * AutoFix RuboCop Layout/HashAlignment * AutoFix RuboCop Layout/IndentationWidth * Regenerate todo * AutoFix RuboCop Layout/SpaceBeforeBlockBraces * AutoFix RuboCop Layout/SpaceBeforeComma * AutoFix RuboCop Layout/SpaceInsideBlockBraces * AutoFix RuboCop Layout/SpaceInsideHashLiteralBraces * AutoFix RuboCop Layout/TrailingEmptyLines * Update ci.yml Co-authored-by: Pieter Oliver <68863060+pieterocp@users.noreply.github.com> * WIP: Remove claude-scratchpad cruft from rubocop todo * Specify files explicity in rubocop rake task * Pin rubocop version to 1.77.0 * AutoFix RuboCop Style/TrailingCommaInHashLiteral * AutoFix RuboCop Style/StringLiteralsInInterpolation * AutoFix RuboCop Style/StringLiterals * AutoFix RuboCop Style/RescueStandardError * AutoFix RuboCop Style/RedundantPercentQ * AutoFix RuboCop Style/RedundantConstantBase * AutoFix RuboCop Style/QuotedSymbols * AutoFix RuboCop Style/PercentLiteralDelimiters * AutoFix RuboCop Style/ParallelAssignment * AutoFix RuboCop Style/MultilineIfModifier * AutoFix RuboCop Style/Lambda * AutoFix RuboCop Style/IfUnlessModifier * AutoFix RuboCop Style/HashSyntax * AutoFix RuboCop Style/GuardClause * AutoFix RuboCop Style/ExpandPathArguments * AutoFix RuboCop Style/BlockDelimiters * AutoFix RuboCop Style/BlockComments * AutoFix RuboCop Lint/UnusedMethodArgument * AutoFix RuboCop Lint/SymbolConversion * Fix auto-gen formatting + RuboCop AutoFix Style/ModuleFunction * Code style --------- Co-authored-by: Pieter Oliver <pieter.oliver@nourishcare.com> Co-authored-by: Pieter Oliver <68863060+pieterocp@users.noreply.github.com>
84 lines
2.4 KiB
Ruby
84 lines
2.4 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe GrapeLogging::Formatters::Rails do
|
|
let(:formatter) { described_class.new }
|
|
let(:severity) { 'INFO' }
|
|
let(:datetime) { Time.new('2018', '03', '02', '10', '35', '04', '+13:00') }
|
|
|
|
let(:exception_data) { ArgumentError.new('Message') }
|
|
let(:hash_data) do
|
|
{
|
|
status: 200,
|
|
time: {
|
|
total: 272.4,
|
|
db: 40.63,
|
|
view: 231.76999999999998
|
|
},
|
|
method: 'GET',
|
|
path: '/api/endpoint',
|
|
host: 'localhost'
|
|
}
|
|
end
|
|
|
|
describe '#call' do
|
|
context 'string data' do
|
|
it 'returns a formatted string' do
|
|
message = formatter.call(severity, datetime, nil, 'value')
|
|
|
|
expect(message).to eq "I [2018-03-02 10:35:04 +1300] INFO -- : value\n"
|
|
end
|
|
end
|
|
|
|
context 'exception data' do
|
|
it 'returns a string with a backtrace' do
|
|
exception_data.set_backtrace(caller)
|
|
|
|
message = formatter.call(severity, datetime, nil, exception_data)
|
|
lines = message.split("\n")
|
|
|
|
expect(lines[0]).to eq 'I [2018-03-02 10:35:04 +1300] INFO -- : Message (ArgumentError)'
|
|
expect(lines[1]).to include '.rb'
|
|
expect(lines.size).to be > 1
|
|
end
|
|
end
|
|
|
|
context 'hash data' do
|
|
it 'returns a formatted string' do
|
|
message = formatter.call(severity, datetime, nil, hash_data)
|
|
|
|
expect(message).to eq "Completed 200 OK in 272.4ms (Views: 231.77ms | DB: 40.63ms)\n"
|
|
end
|
|
|
|
it 'includes params if included (from GrapeLogging::Loggers::FilterParameters)' do
|
|
hash_data.merge!(
|
|
params: {
|
|
'some_param' => {
|
|
value_1: '123',
|
|
value_2: '456'
|
|
}
|
|
}
|
|
)
|
|
|
|
message = formatter.call(severity, datetime, nil, hash_data)
|
|
lines = message.split("\n")
|
|
|
|
expected_output =
|
|
if RUBY_VERSION >= '3.4'
|
|
' Parameters: {"some_param" => {value_1: "123", value_2: "456"}}'
|
|
else
|
|
' Parameters: {"some_param"=>{:value_1=>"123", :value_2=>"456"}}'
|
|
end
|
|
expect(lines.first).to eq expected_output
|
|
expect(lines.last).to eq 'Completed 200 OK in 272.4ms (Views: 231.77ms | DB: 40.63ms)'
|
|
end
|
|
end
|
|
|
|
context 'unhandled data' do
|
|
it 'returns the #inspect string representation' do
|
|
message = formatter.call(severity, datetime, nil, [1, 2, 3])
|
|
|
|
expect(message).to eq "[1, 2, 3]\n"
|
|
end
|
|
end
|
|
end
|
|
end
|