Sha256: e38a47129e07d9a026951cbf09538bc47cf73722b9be5747791670d7d08a0d79

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require_relative '../test_helper'

# Unit Test for SemanticLogger::Appender::Bugsnag
module Appender
  class HoneybadgerTest < Minitest::Test
    describe SemanticLogger::Appender::Honeybadger do
      before do
        @appender                      = SemanticLogger::Appender::Honeybadger.new(level: :trace)
        @message                       = 'AppenderHoneybadgerTest log message'
        SemanticLogger.backtrace_level = :error
      end

      SemanticLogger::LEVELS.each do |level|
        it "sends #{level} message" do
          hash = nil
          Honeybadger.stub(:notify, ->(h) { hash = h }) do
            @appender.send(level, @message)
          end
          assert_equal @message, hash[:error_message]
          assert_equal 'SemanticLogger::Appender::Honeybadger', hash[:error_class]

          if %i[error fatal].include?(level)
            assert hash.key?(:backtrace)
          else
            refute hash.key?(:backtrace)
          end
          assert_equal true, hash.key?(:context)
          assert_equal level, hash[:context][:level]
        end

        it "sends #{level} exceptions" do
          error     = RuntimeError.new('Oh no, Error.')
          exception = hash = nil
          Honeybadger.stub(:notify, ->(exc, h) { exception = exc; hash = h }) do
            @appender.send(level, @message, error)
          end

          assert_equal error.class.to_s, exception.class.to_s
          assert_equal error.message, exception.message
          assert_equal @message, hash[:message], hash
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
semantic_logger-4.3.1 test/appender/honeybadger_test.rb
semantic_logger-4.3.0 test/appender/honeybadger_test.rb
semantic_logger-4.2.2 test/appender/honeybadger_test.rb
semantic_logger-4.2.1 test/appender/honeybadger_test.rb