Permalink
Browse files

Add support for captureMessage and captureException (fixes GH-25)

  • Loading branch information...
1 parent c1d2b49 commit 9a3aa8226e9a986fa717883493413aaa0be934ec @dcramer dcramer committed Oct 3, 2012
Showing with 68 additions and 4 deletions.
  1. +12 −4 lib/raven.rb
  2. +11 −0 lib/raven/event.rb
  3. +16 −0 spec/raven/event_spec.rb
  4. +29 −0 spec/raven/raven_spec.rb
View
@@ -72,21 +72,29 @@ def capture(&block)
rescue Error => e
raise # Don't capture Raven errors
rescue Exception => e
- evt = Event.capture_exception(e)
- send(evt) if evt
+ self.captureException(e)
raise
end
else
# Install at_exit hook
at_exit do
if $!
logger.debug "Caught a post-mortem exception: #{$!.inspect}"
- evt = Event.capture_exception($!)
- send(evt) if evt
+ self.captureException($!)
end
end
end
end
+ def captureException(exception)
+ evt = Event.capture_exception(exception)
+ send(evt) if evt
+ end
+
+ def captureMessage(message)
+ evt = Event.capture_message(message)
+ send(evt) if evt
+ end
+
end
end
View
@@ -150,6 +150,17 @@ def self.capture_rack_exception(exc, rack_env, configuration=nil, &block)
end
end
+ def self.capture_message(message, configuration=nil)
+ configuration ||= Raven.configuration
+ self.new({}, configuration) do |evt|
+ evt.message = message
+ evt.level = :error
+ evt.interface :message do |int|
+ int.message = message
+ end
+ end
+ end
+
# For cross-language compat
class << self
alias :captionException :capture_exception
View
@@ -0,0 +1,16 @@
+require File::expand_path('../../spec_helper', __FILE__)
+require 'raven'
+
+describe Raven::Event do
+ before do
+ @send = double("send")
+ @event = double("event")
+ end
+
+ it 'capture_message should build event' do
+ message = "Test message"
+ evt = Raven::Event.capture_message(message)
+ evt.message.should eq(message)
+ evt.level.should eq(40)
+ end
+end
View
@@ -0,0 +1,29 @@
+require File::expand_path('../../spec_helper', __FILE__)
+require 'raven'
+
+describe Raven do
+ before do
+ @send = double("send")
+ @event = double("event")
+ Raven.stub(:send) { @send }
+ Raven::Event.stub(:capture_message) { @event }
+ Raven::Event.stub(:capture_exception) { @event }
+ end
+
+ it 'captureMessage should send result of Event.capture_message' do
+ message = "Test message"
+ Raven::Event.should_receive(:capture_message).with(message)
+ Raven.should_receive(:send).with(@event)
+
+ Raven.captureMessage(message)
+ end
+
+ it 'captureException should send result of Event.capture_exception' do
+ exception = build_exception()
+
+ Raven::Event.should_receive(:capture_exception).with(exception)
+ Raven.should_receive(:send).with(@event)
+
+ Raven.captureException(exception)
+ end
+end

0 comments on commit 9a3aa82

Please sign in to comment.