Sha256: 5d3411d554e9ca96741c5d38d8b927738ceb12d16cc640bd7fb19c2bea5bb84a

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require_relative 'test_helper'

# Unit Test for SemanticLogger::Appender::Bugsnag
#
class AppenderBugsnagTest < Minitest::Test
  context SemanticLogger::Appender::Bugsnag do
    setup do
      @appender = SemanticLogger::Appender::Bugsnag.new(:warn)
      @message  = 'AppenderBugsnagTest log message'
    end

    (SemanticLogger::LEVELS - [:warn, :error]).each do |level|
      should "not send :#{level} notifications to Bugsnag" do
        message = hash = nil
        Bugsnag.stub(:notify, -> msg, h { message = msg; hash = h }) do
          @appender.send(level, "AppenderBugsnagTest #{level.to_s} message")
        end
        assert_nil message
        assert_nil hash
      end
    end

    should "send error notifications to Bugsnag with severity" do
      message = hash = nil
      Bugsnag.stub(:notify, -> msg, h { message = msg; hash = h }) do
        @appender.error @message
      end
      assert_equal RuntimeError.new(@message), message
      assert_equal 'error', hash[:severity]
    end

    should 'send warn notifications to Bugsnag replace warn severity with warning' do
      message = hash = nil
      Bugsnag.stub(:notify, -> msg, h { message = msg; hash = h }) do
        @appender.warn @message
      end
      assert_equal RuntimeError.new(@message), message
      assert_equal 'warning', hash[:severity]
    end

    should 'send notification to Bugsnag with custom attributes' do
      message = hash = nil
      Bugsnag.stub(:notify, -> msg, h { message = msg; hash = h }) do
        @appender.error @message, {:key1 => 1, :key2 => 'a'}
      end
      assert_equal RuntimeError.new(@message), message
      assert_equal(1, hash[:key1], hash)
      assert_equal('a', hash[:key2], hash)
    end

    should 'send notification to Bugsnag with exception' do
      message = hash = nil
      error = RuntimeError.new('Hello World')
      Bugsnag.stub(:notify, -> msg, h { message = msg; hash = h }) do
        @appender.error error
      end
      assert_equal error, message
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
semantic_logger-2.15.0 test/appender_bugsnag_test.rb