Skip to content

Commit

Permalink
Some basic specs. Newrelic support complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
lpradovera committed Nov 1, 2013
1 parent b288e7c commit dfef696
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/adhearsion/reporter/hoptoad_notifier.rb
Expand Up @@ -14,11 +14,11 @@ def init
def notify(ex)
response = @notifier.post!(ex) if Reporter.config.enable
if !response.errors.empty? || !(200..299).include?(response.status.to_i)
logger.error "Error posting exception to #{config.url}! Response code #{response.status}"
logger.error "Error posting exception to #{Reporter.config.url}! Response code #{response.status}"
response.errors.each do |error|
logger.error "#{error}"
end
logger.warn "Original exception message: #{e.message}"
logger.warn "Original exception message: #{ex.message}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/adhearsion/reporter/newrelic_notifier.rb
@@ -1,6 +1,6 @@
# encoding: utf-8

require 'newrelic_rpm'
require 'new_relic/control'

module Adhearsion
class Reporter
Expand Down
62 changes: 41 additions & 21 deletions spec/reporter_spec.rb
Expand Up @@ -20,11 +20,7 @@ def notify(ex)
before(:each) do
Adhearsion::Reporter.config.notifier = DummyNotifier
Adhearsion::Plugin.init_plugins
Adhearsion::Events.register_handler :event, EventClass do |event|
raise ExceptionClass
end
Adhearsion::Events.trigger_immediately :event, EventClass.new
Adhearsion::Events.clear_handlers :event, EventClass
Adhearsion::Events.trigger_immediately :exception, ExceptionClass.new
end

it "calls init on the notifier instance" do
Expand All @@ -37,20 +33,44 @@ def notify(ex)
end
end

# context "with a NewrelicNotifier" do
# before(:each) do
# Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::NewrelicNotifier
# Adhearsion::Reporter.config.newrelic.license_key = 'BLAH'
# Adhearsion::Reporter.config.newrelic.app_name = 'AhnRepTest'
# end

# it "does stuff" do
# Adhearsion::Plugin.init_plugins
# Adhearsion::Events.register_handler :event, EventClass do |event|
# raise ExceptionClass
# end
# Adhearsion::Events.trigger_immediately :event, EventClass.new
# Adhearsion::Events.clear_handlers :event, EventClass
# end
# end
context "with a HoptoadNotifier" do
before(:each) do
Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::HoptoadNotifier
end

it "should initialize correctly" do
Toadhopper.should_receive(:new).with(Adhearsion::Reporter.config.api_key, notify_host: Adhearsion::Reporter.config.url)
Adhearsion::Plugin.init_plugins
end

it "should notify Airbrake" do
mock_notifier = double('notifier')
Toadhopper.should_receive(:new).and_return(mock_notifier)
event_error = ExceptionClass.new
mock_notifier.should_receive(:post!).at_least(:once).with(event_error).and_return(double('response').as_null_object)
Adhearsion::Plugin.init_plugins
Adhearsion::Events.trigger_immediately :exception, event_error
end
end

context "with a NewrelicNotifier" do
before(:each) do
Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::NewrelicNotifier
end

it "should initialize correctly" do
NewRelic::Agent.should_receive(:manual_start).with(Adhearsion::Reporter.config.newrelic.to_hash)
Adhearsion::Plugin.init_plugins
end

it "should notify Newrelic" do
NewRelic::Agent.should_receive(:manual_start)

event_error = ExceptionClass.new
NewRelic::Agent.should_receive(:notice_error).at_least(:once).with(event_error)

Adhearsion::Plugin.init_plugins
Adhearsion::Events.trigger_immediately :exception, event_error
end
end
end

0 comments on commit dfef696

Please sign in to comment.