Sha256: beedd463c1b4f312fba1a67068eaa34668254575be6ba063d31abe915a9a3f0b

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 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\":{\"error\":{\"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

21 entries across 21 versions & 1 rubygems

Version Path
timber-2.5.1 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.5.0 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.4.0 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.3.4 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.3.3 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.3.2 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.3.1 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.3.0 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.2.3 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.2.2 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.2.1 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.2.0 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.10 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.9 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.8 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.7 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.6 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.5 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.4 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb
timber-2.1.3 spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb