From 1fa42722edfcd93880a66924f767d51d9dbd5321 Mon Sep 17 00:00:00 2001 From: Ryan Buckley Date: Fri, 16 Sep 2016 12:06:41 -0700 Subject: [PATCH] Add spec for testing exception logging --- .../lib/grape/middleware/logger_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/integration/lib/grape/middleware/logger_spec.rb b/spec/integration/lib/grape/middleware/logger_spec.rb index 6d7184c..fb001e2 100644 --- a/spec/integration/lib/grape/middleware/logger_spec.rb +++ b/spec/integration/lib/grape/middleware/logger_spec.rb @@ -21,6 +21,22 @@ subject.call!(env) end + context 'when an exception occurs' do + it 'logs all parts of the request including the error class' do + expect(subject.logger).to receive(:info).with '' + expect(subject.logger).to receive(:info).with %Q(Started POST "/api/1.0/users" at #{subject.start_time}) + expect(subject.logger).to receive(:info).with %Q(Processing by TestAPI/users) + expect(subject.logger).to receive(:info).with %Q( Parameters: {"id"=>"101001", "secret"=>"[FILTERED]", "customer"=>[], "name"=>"foo", "password"=>"[FILTERED]"}) + expect(subject.logger).to receive(:info).with %Q( ArgumentError: Whoops) + expect(subject.logger).to receive(:info).with /Completed 500 in \d+\.\d+ms/ + expect(subject.logger).to receive(:info).with '' + expect(subject.app).to receive(:call).and_raise(ArgumentError, 'Whoops') + expect { + subject.call!(env) + }.to raise_error(ArgumentError) + end + end + describe 'the "processing by" section' do before { subject.call!(env) }