Sha256: 1d3aee4af97f1701cc216a36f222150b31817df7e006be211f63cb85d7c1bd70

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'test_helper'
require 'httparty'

class WebhookNotifierTest < ActiveSupport::TestCase

  test "should send webhook notification if properly configured" do
    ExceptionNotifier::WebhookNotifier.stubs(:new).returns(Object.new)
    webhook = ExceptionNotifier::WebhookNotifier.new({:url => 'http://localhost:8000'})
    webhook.stubs(:call).returns(fake_response)
    response = webhook.call(fake_exception)

    assert_not_nil response
    assert_equal response[:status], 200
    assert_equal response[:body][:exception][:error_class], "ZeroDivisionError"
    assert response[:body][:exception][:message].include? "divided by 0"
    assert response[:body][:exception][:backtrace].include? "/exception_notification/test/webhook_notifier_test.rb:48"
  end

  private

  def fake_response
    {
      :status => 200,
      :body => {
        :exception => {
          :error_class => 'ZeroDivisionError',
          :message => 'divided by 0',
          :backtrace => '/exception_notification/test/webhook_notifier_test.rb:48:in `/'
        }
      }
    }
  end

  def fake_exception
    exception = begin
      5/0
    rescue Exception => e
      e
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
exception_notification-4.0.0 test/exception_notifier/webhook_notifier_test.rb
exception_notification-4.0.0.rc1 test/exception_notifier/webhook_notifier_test.rb