Sha256: 618e6a252b10f801ab3bc56ead87aab26a208182136138b75499a6522a1c8d46

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

require "spec_helper"

describe Timber::Probes::ActionDispatchDebugExceptions do
  describe "#{described_class}::*InstanceMethods" do
    describe "#log_error" 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

      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

        Timecop.freeze(time) { example.run }

        Object.send(:remove_const, :ExceptionController)
      end

      it "should set the context" do
        mock_class
        dispatch_rails_request("/exception")
        # Because constantly updating the line numbers sucks :/
        expect(io.string).to include("RuntimeError (boom):\\n\\n")
        expect(io.string).to include("@timber.io")
        expect(io.string).to include("\"event\":{\"exception\":{\"name\":\"RuntimeError\",\"message\":\"boom\",\"backtrace\":[\"")
      end

      def mock_class
        klass = defined?(::ActionDispatch::DebugExceptions) ? ::ActionDispatch::DebugExceptions : ::ActionDispatch::ShowExceptions
        allow_any_instance_of(klass).to receive(:logger).and_return(logger)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
timber-1.0.13 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.12 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.11 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.10 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.9 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.8 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.7 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.6 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.5 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.4 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timber-1.0.3 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb
timberio-1.0.3 spec/timber/probes/action_dispatch_debug_exceptions_spec.rb