spec/faraday/response/logger_spec.rb in faraday-2.6.0 vs spec/faraday/response/logger_spec.rb in faraday-2.7.0
- old
+ new
@@ -62,10 +62,19 @@
it 'delegates logging to the formatter' do
expect(formatter).to receive(:request).with(an_instance_of(Faraday::Env))
expect(formatter).to receive(:response).with(an_instance_of(Faraday::Env))
conn.get '/hello'
end
+
+ context 'when no route' do
+ it 'delegates logging to the formatter' do
+ expect(formatter).to receive(:request).with(an_instance_of(Faraday::Env))
+ expect(formatter).to receive(:error).with(an_instance_of(Faraday::Adapter::Test::Stubs::NotFound))
+
+ expect { conn.get '/noroute' }.to raise_error(Faraday::Adapter::Test::Stubs::NotFound)
+ end
+ end
end
context 'with custom formatter' do
let(:formatter_class) do
Class.new(Faraday::Logging::Formatter) do
@@ -92,10 +101,20 @@
it 'logs method and url' do
conn.get '/hello', nil, accept: 'text/html'
expect(string_io.string).to match('GET http:/hello')
end
+ it 'logs status' do
+ conn.get '/hello', nil, accept: 'text/html'
+ expect(string_io.string).to match('Status 200')
+ end
+
+ it 'does not log error message by default' do
+ expect { conn.get '/noroute' }.to raise_error(Faraday::Adapter::Test::Stubs::NotFound)
+ expect(string_io.string).not_to match(%(no stubbed request for get http:/noroute))
+ end
+
it 'logs request headers by default' do
conn.get '/hello', nil, accept: 'text/html'
expect(string_io.string).to match(%(Accept: "text/html))
end
@@ -183,9 +202,18 @@
it 'logs filter body' do
conn.get '/filtered_body', nil, accept: 'text/html'
expect(string_io.string).to match(%(soylent green is))
expect(string_io.string).to match(%(tasty))
expect(string_io.string).not_to match(%(people))
+ end
+ end
+
+ context 'when logging errors' do
+ let(:logger_options) { { errors: true } }
+
+ it 'logs error message' do
+ expect { conn.get '/noroute' }.to raise_error(Faraday::Adapter::Test::Stubs::NotFound)
+ expect(string_io.string).to match(%(no stubbed request for get http:/noroute))
end
end
context 'when using log_level' do
let(:logger_options) { { bodies: true, log_level: :debug } }