Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 9a3aa8226e9a986fa717883493413aaa0be934ec 1 parent c1d2b49
@dcramer dcramer authored
View
16 lib/raven.rb
@@ -72,8 +72,7 @@ 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
@@ -81,12 +80,21 @@ def capture(&block)
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
11 lib/raven/event.rb
@@ -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
16 spec/raven/event_spec.rb
@@ -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
29 spec/raven/raven_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.