Sha256: 90ca037bfc5da19e923699b0bd108566911c76e88d9212d4f40659cb905fa854

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

require 'test_helper'

class BackgroundExceptionNotificationTest < ActiveSupport::TestCase
  setup do
    begin
      1/0
    rescue => e
      @exception = e
      @mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
    end
  end

  test "should have raised an exception" do
    assert_not_nil @exception
  end

  test "should have generated a notification email" do
    assert_not_nil @mail
  end

  test "mail should have a from address set" do
    assert @mail.from == ["dummynotifier@example.com"]
  end

  test "mail should have a to address set" do
    assert @mail.to == ["dummyexceptions@example.com"]
  end

  test "mail should have a descriptive subject" do
    assert @mail.subject.include? "[Dummy ERROR]  (ZeroDivisionError) \"divided by 0\""
  end

  test "mail should say exception was raised in background" do
    assert @mail.body.include? "A ZeroDivisionError occurred in background"
  end

  test "mail should contain backtrace in body" do
    assert @mail.body.include? "test/background_exception_notification_test.rb:6"
  end

  test "mail should not contain any attachments" do
    assert @mail.attachments == []
  end

  test "should not send notification if one of ignored exceptions" do
    begin
      raise ActiveRecord::RecordNotFound
    rescue => e
      @ignored_exception = e
      unless ExceptionNotifier.default_ignore_exceptions.include?(@ignored_exception.class)
        @ignored_mail = ExceptionNotifier::Notifier.background_exception_notification(@ignored_exception)
      end
    end

    assert @ignored_exception.class.inspect == "ActiveRecord::RecordNotFound"
    assert_nil @ignored_mail
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
exception_notification-2.5.2 test/background_exception_notification_test.rb
exception_notification-2.5.1 test/background_exception_notification_test.rb
exception_notification-2.5.0 test/background_exception_notification_test.rb