Sha256: a7eadd57a5d7572a6f9f8faab040a97519933cbc5747ad525f727bcce7e472fd

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require "spec_helper"

describe Timber::Probes::RailsRackLogger do
  describe described_class::InstanceMethods do
    let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
    let(:io) { StringIO.new }
    let(:logger) do
      logger = Timber::Logger.new(io)
      logger.level = ::Logger::INFO
      logger
    end

    around(:each) do |example|
      class RailsRackLoggerController < ActionController::Base
        layout nil

        def index
          render json: {}
        end

        def method_for_action(action_name)
          action_name
        end
      end

      ::RailsApp.routes.draw do
        get '/rails_rack_logger' => 'rails_rack_logger#index'
      end

      Timecop.freeze(time) { example.run }

      Object.send(:remove_const, :RailsRackLoggerController)
    end

    describe "#started_request_message" do
      it "should add the request event" do
        allow(::Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("production")) # Rails 3.2.X
        allow(::Rails).to receive(:logger).and_return(logger) # Rails 3.2.X
        allow_any_instance_of(::Rails::Rack::Logger).to receive(:logger).and_return(logger)
        dispatch_rails_request("/rails_rack_logger")
        expect(io.string).to start_with("Started GET \"/rails_rack_logger\" for 123.456.789.10 @metadata {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\"")
        expect(io.string).to include("\"event\":{\"server_side_app\":{\"http_server_request\":{\"host\":\"example.org\",\"method\":\"GET\",\"path\":\"/rails_rack_logger\",\"port\":80,\"headers\":{\"remote_addr\":\"123.456.789.10\",\"request_id\":\"unique-request-id-1234\"}}}")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timber-1.1.8 spec/timber/probes/rails_rack_logger_spec.rb
timber-1.1.7 spec/timber/probes/rails_rack_logger_spec.rb