Sha256: a70cd02d1a3ce6c8d9238db3b4cde3ed0124a419e821f4233a2aca96a8d628d1

Contents?: true

Size: 1.51 KB

Versions: 17

Compression:

Stored size: 1.51 KB

Contents

require "spec_helper"

if defined?(::ActionDispatch)
  describe Timber::Integrations::ActionDispatch::DebugExceptions 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::DEBUG
      logger
    end

    describe "#insert!" do
      around(:each) do |example|
        class ExceptionController < ActionController::Base
          layout nil

          def index
            raise "boom"
          end

          def method_for_action(action_name)
            action_name
          end
        end

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

        with_rails_logger(logger) do
          Timecop.freeze(time) { example.run }
        end

        Object.send(:remove_const, :ExceptionController)
      end

      it "should log an exception event once" do
        expect { dispatch_rails_request("/exception") }.to raise_error(RuntimeError)

        lines = clean_lines(io.string.split("\n"))
        expect(lines.length).to eq(3)
        expect(lines[2]).to start_with('RuntimeError (boom) @metadata {"level":"fatal",')
        expect(lines[2]).to include("\"event\":{\"server_side_app\":{\"exception\":{\"name\":\"RuntimeError\",\"message\":\"boom\",\"backtrace\":[")
      end

      # Remove blank lines since Rails does this to space out requests in the logs
      def clean_lines(lines)
        lines.select { |line| !line.start_with?(" @metadat") }
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
timber-2.0.17 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.16 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.15 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.14 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.12 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.11 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.10 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.9 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.8 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.7 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.6 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.5 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.4 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.3 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.2 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.1 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.0.0 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb