Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Call the error handler off the per-test registry.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Aug 28, 2015
1 parent 2590293 commit ea73700
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/lita/handler/chat_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def dispatch_to_route(route, robot, message)
handler = new(robot)
route.callback.call(handler, response)
rescue => error
log_error(error)
log_error(robot, error)
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/lita/handler/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def translate(key, hash = {})
alias_method :t, :translate

# Logs an error raised by a plugin.
def log_error(error)
Lita.config.robot.error_handler.call(error)
def log_error(robot, error)
robot.config.robot.error_handler.call(error)
Lita.logger.error I18n.t(
"lita.handler.exception",
handler: name,
Expand Down
2 changes: 1 addition & 1 deletion lib/lita/handler/event_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def trigger(robot, event_name, payload = {})
begin
callback.call(new(robot), payload)
rescue => error
log_error(error)
log_error(robot, error)
end
end.any?
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lita/handler/chat_router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def self.name

context "when the handler raises an exception" do
it "calls the error handler with the exception as argument" do
expect(Lita.config.robot.error_handler).to receive(:call).with(instance_of(TypeError))
expect(registry.config.robot.error_handler).to receive(:call).with(instance_of(TypeError))

expect { send_message("boom!") }.to raise_error(TypeError)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lita/handler/event_router_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "spec_helper"

describe Lita::Handler::EventRouter do
let(:robot) { instance_double("Lita::Robot", name: "Lita") }
describe Lita::Handler::EventRouter, lita: true do
let(:robot) { Lita::Robot.new(registry) }

subject do
Class.new do
Expand Down Expand Up @@ -91,7 +91,7 @@ def greet(payload)

it "reports callback exceptions to the error handler" do
allow(robot).to receive(:send_message)
expect(Lita.config.robot.error_handler).to receive(:call).twice
expect(registry.config.robot.error_handler).to receive(:call).twice
subject.trigger(robot, :multiple_errors)
end
end
Expand All @@ -109,7 +109,7 @@ def greet(payload)

it "re-raises callback exceptions immediately" do
allow(robot).to receive(:send_message)
expect(Lita.config.robot.error_handler).to receive(:call).once
expect(registry.config.robot.error_handler).to receive(:call).once
expect { subject.trigger(robot, :multiple_errors) }.to raise_error(ArgumentError, "first")
end
end
Expand Down

0 comments on commit ea73700

Please sign in to comment.