Permalink
Browse files

handles exceptions with #to_hash properly

  • Loading branch information...
1 parent ff43150 commit 1b65dd77e09614d117cc41dfe25eb6192de3745f @thomasjachmann thomasjachmann committed Apr 21, 2011
Showing with 15 additions and 5 deletions.
  1. +2 −5 lib/hoptoad_notifier.rb
  2. +13 −0 test/notifier_test.rb
View
@@ -131,11 +131,8 @@ def send_notice(notice)
def build_notice_for(exception, opts = {})
exception = unwrap_exception(exception)
- if exception.respond_to?(:to_hash)
- opts = opts.merge(exception.to_hash)
- else
- opts = opts.merge(:exception => exception)
- end
+ opts = opts.merge(:exception => exception)
+ opts = opts.merge(exception.to_hash) if exception.respond_to?(:to_hash)
Notice.new(configuration.merge(opts))
end
View
@@ -82,6 +82,19 @@ def set_development_env
assert_sent(notice, notice_args)
end
+ should "create and send a notice for an exception that responds to to_hash" do
+ set_public_env
+ exception = build_exception
+ notice = stub_notice!
+ notice_args = { :error_message => 'uh oh' }
+ exception.stubs(:to_hash).returns(notice_args)
+ stub_sender!
+
+ HoptoadNotifier.notify(exception)
+
+ assert_sent(notice, notice_args.merge(:exception => exception))
+ end
+
should "create and sent a notice for an exception and hash" do
set_public_env
exception = build_exception

0 comments on commit 1b65dd7

Please sign in to comment.