test/unit/notifier_test.rb in honeybadger-1.3.1 vs test/unit/notifier_test.rb in honeybadger-1.4.0

- old
+ new

@@ -1,24 +1,21 @@ require 'test_helper' -class NotifierTest < Honeybadger::UnitTest +class NotifierTest < Test::Unit::TestCase class OriginalException < Exception end class ContinuedException < Exception end - include DefinesConstants - def setup super reset_config end def assert_sent(notice, notice_args) assert_received(Honeybadger::Notice, :new) {|expect| expect.with(has_entries(notice_args)) } - assert_received(notice, :to_json) assert_received(Honeybadger.sender, :send_to_honeybadger) {|expect| expect.with(notice.to_json) } end def set_public_env Honeybadger.configure { |config| config.environment_name = 'production' } @@ -57,10 +54,33 @@ assert_received(Honeybadger::Sender, :new) { |expect| expect.with(configuration) } assert_equal sender, Honeybadger.sender end + should "create and send a notice asynchronously" do + set_public_env + notice = stub_notice! + notice_args = { :error_message => 'uh oh' } + + async_expectation = stub(:received => true) + async_handler = Proc.new do |notice| + async_expectation.received + notice.deliver + end + + Honeybadger.configure do |config| + config.async = async_handler + end + + stub_sender! + + Honeybadger.notify(notice_args) + + assert_received(async_expectation, :received) + assert_sent(notice, notice_args) + end + should "create and send a notice for an exception" do set_public_env exception = build_exception stub_sender! notice = stub_notice! @@ -154,10 +174,10 @@ should "pass config to created notices" do exception = build_exception config_opts = { 'one' => 'two', 'three' => 'four' } notice = stub_notice! stub_sender! - Honeybadger.configuration = stub('config', :merge => config_opts, :public? => true) + Honeybadger.configuration = stub('config', :merge => config_opts, :public? => true, :async? => false) Honeybadger.notify(exception) assert_received(Honeybadger::Notice, :new) do |expect| expect.with(has_entries(config_opts))