From 58b58cfe4abaa651cb7c7694cfa3fe3096a28768 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Tue, 30 Jan 2018 12:05:42 +0100 Subject: [PATCH] Test sane behavior when trying to set fields or tags causing exception in Rack::Middleware --- spec/rackstash/rack/middleware_spec.rb | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/spec/rackstash/rack/middleware_spec.rb b/spec/rackstash/rack/middleware_spec.rb index 0119653..128beea 100644 --- a/spec/rackstash/rack/middleware_spec.rb +++ b/spec/rackstash/rack/middleware_spec.rb @@ -137,6 +137,22 @@ describe Rackstash::Rack::Middleware do 'method' => 'GET' ) end + + context 'on merge errors' do + it 'raises an error' do + args[:request_fields] = ->(_request){ raise 'Oh No!' } + + expect { get('/stuff') }.to raise_error RuntimeError, 'Oh No!' + expect(log.last).to include( + 'path' => '/stuff', + 'method' => 'GET', + 'status' => 500, + 'error' => 'RuntimeError', + 'error_message' => 'Oh No!', + 'error_trace' => %r{\A#{__FILE__}:#{__LINE__ - 9}:in} + ) + end + end end context 'with request_tags' do @@ -148,6 +164,22 @@ describe Rackstash::Rack::Middleware do expect(log.last).to include('tags' => ['foo', 'STUFF']) end + + context 'on merge errors' do + it 'raises an error' do + args[:request_tags] = ->(_request){ raise 'Oh No!' } + + expect { get('/stuff') }.to raise_error RuntimeError, 'Oh No!' + expect(log.last).to include( + 'path' => '/stuff', + 'method' => 'GET', + 'status' => 500, + 'error' => 'RuntimeError', + 'error_message' => 'Oh No!', + 'error_trace' => %r{\A#{__FILE__}:#{__LINE__ - 9}:in} + ) + end + end end context 'with response fields' do @@ -172,6 +204,22 @@ describe Rackstash::Rack::Middleware do expect(log.last).to include 'path' => '/stuff' end + + context 'on merge errors' do + it 'raises an error' do + args[:response_fields] = ->(_headers){ raise 'Oh No!' } + + expect { get('/stuff') }.to raise_error RuntimeError, 'Oh No!' + expect(log.last).to include( + 'path' => '/stuff', + 'method' => 'GET', + 'status' => 500, + 'error' => 'RuntimeError', + 'error_message' => 'Oh No!', + 'error_trace' => %r{\A#{__FILE__}:#{__LINE__ - 9}:in} + ) + end + end end context 'with response_tags' do