Sha256: d562af5abe32c68f5520a0ec574f2354b8de4b722795f41b697620d05df82748

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe RightSupport::Rack::RequestLogger do
  class OhNoes < Exception; end

  before(:each) do
    @app = flexmock('Rack app')
    @app.should_receive(:call).and_return([200, {}, 'body']).by_default
    @logger = mock_logger
    @env = {'rack.logger' => @logger}
    @middleware = RightSupport::Rack::RequestLogger.new(@app)
  end

  context :initialize do
    context 'without :logger option' do
      it 'uses rack.logger' do
        @logger.should_receive(:info)
        @middleware.call(@env).should == [200, {}, 'body']
      end
    end
  end

  context :call do
    context 'when the app raises an exception' do
      before(:each) do
        @app.should_receive(:call).and_raise(OhNoes)
      end

      it 'logs the exception' do
        @logger.should_receive(:error)
        lambda {
          @middleware.call({})
        }.should raise_error
      end
    end

    context 'when Sinatra stores an exception' do
      before(:each) do
        @app.should_receive(:call).and_return([500, {}, 'body'])
        @env['sinatra.error'] = OhNoes.new
      end

      it 'logs the exception' do
        @logger.should_receive(:info)
        @logger.should_receive(:error)
        @middleware.call(@env)
      end
    end

    context 'Shard ID logging' do
      before(:each) do
        @logger = mock_logger
      end

      it 'logs X-Shard header if it is present' do
        @env['HTTP_X_SHARD'] = '9'
        @logger.should_receive(:info).with(FlexMock.on { |arg| arg.should =~ /Shard: 9;/ } )
        @middleware.send(:log_request_begin, @logger, @env)
      end

      it 'logs "default" if X-Shard header is absent' do
        @logger.should_receive(:info).with(FlexMock.on { |arg| arg.should =~ /Shard: default;/ } )
        @middleware.send(:log_request_begin, @logger, @env)
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
right_support-2.8.12 spec/rack/request_logger_spec.rb
right_support-2.8.11 spec/rack/request_logger_spec.rb
right_support-2.8.10 spec/rack/request_logger_spec.rb
right_support-2.8.9 spec/rack/request_logger_spec.rb
right_support-2.8.8 spec/rack/request_logger_spec.rb
right_support-2.8.7 spec/rack/request_logger_spec.rb
right_support-2.8.6 spec/rack/request_logger_spec.rb
right_support-2.8.3 spec/rack/request_logger_spec.rb
right_support-2.8.2 spec/rack/request_logger_spec.rb
right_support-2.8.1 spec/rack/request_logger_spec.rb
right_support-2.8.0 spec/rack/request_logger_spec.rb
right_support-2.7.0 spec/rack/request_logger_spec.rb