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

Commit

Permalink
WIP: splitting out dispatch_to method so that can be tested against f…
Browse files Browse the repository at this point in the history
…or the 'doesnt_route' catch all rspec thinger
  • Loading branch information
charleseff committed Aug 26, 2013
1 parent 5bf8812 commit bda0523
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/lita/handler.rb
Expand Up @@ -51,19 +51,7 @@ def routes
# @param message [Lita::Message] The incoming message.
# @return [void]
def dispatch(robot, message)
routes.select { |r| route_applies?(r, message, robot) }.each do |route|
log_dispatch(route)

begin
new(robot).public_send(
route.method_name,
build_response(message, route)
)
rescue Exception => e
log_dispatch_error(e)
raise e if rspec_loaded?
end
end
routes.select { |r| route_applies?(r, message, robot) }.each { |route| dispatch_to(route, robot, message) }
end

# Creates a new {Lita::HTTPRoute} which is used to define an HTTP route
Expand Down Expand Up @@ -95,6 +83,20 @@ def namespace

private

def dispatch_to(route, robot, message)
log_dispatch(route)

begin
new(robot).public_send(
route.method_name,
build_response(message, route)
)
rescue Exception => e
log_dispatch_error(e)
raise e if rspec_loaded?
end
end

# Builds a response object for an incoming message.
def build_response(message, route)
Response.new(message, matches: message.match(route.pattern))
Expand Down

0 comments on commit bda0523

Please sign in to comment.