Fix the specs

This commit is contained in:
Sami Samhuri 2025-06-28 07:14:06 -04:00
parent 16062114b1
commit d8d3f3ca1e
No known key found for this signature in database
2 changed files with 11 additions and 6 deletions

View file

@ -37,7 +37,7 @@ describe GrapeLogging::Formatters::Rails do
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 'grape_logging'
expect(lines[1]).to include '.rb'
expect(lines.size).to be > 1
end
end
@ -62,7 +62,12 @@ describe GrapeLogging::Formatters::Rails do
message = formatter.call(severity, datetime, nil, hash_data)
lines = message.split("\n")
expect(lines.first).to eq ' Parameters: {"some_param"=>{:value_1=>"123", :value_2=>"456"}}'
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

View file

@ -4,12 +4,12 @@ require 'ostruct'
describe GrapeLogging::Loggers::Response do
context 'with a parseable JSON body' do
let(:response) do
OpenStruct.new(body: [%q{{"one": "two", "three": {"four": 5}}}])
OpenStruct.new(body: [{"one": "two", "three": {"four": 5}}])
end
it 'returns an array of parseable JSON objects' do
it 'returns an array of parsed JSON objects' do
expect(subject.parameters(nil, response)).to eq({
response: [response.body.first.dup]
response: [response.body.first],
})
end
end
@ -21,7 +21,7 @@ describe GrapeLogging::Loggers::Response do
it 'just returns the body' do
expect(subject.parameters(nil, response)).to eq({
response: response.body.dup
response: response.body,
})
end
end