Configurable routes

Skip to first unread message

Jul 28, 2015, 4:07:43 PM7/28/15
to Lita
Hi all,

I need to create a route the pattern of which needs to be configurable. The documentation for the :loaded event states that "This can be used as a hook point for handlers to define routes that depend on user configuration not known until runtime", so I tried the following:

on(:loaded) do
MyHandler.route config.my_pattern, :my_method, ...

However, it this appears to cause the route to be created multiple times (in my specs, I can see that using robot.handlers.first.routes). Is this not the way to do this? If not, what is?

Thanks for any hint!

Jimmy Cuadra

Jul 28, 2015, 5:15:37 PM7/28/15
to, Lita
Hi Ingo,

I've done this in a few of my handlers. You're on the right track. I did it by having a method call that defines all the routes instead of having them inline in the class body, so that all the routes can be cleared and then regenerated for each test case:

before do

Take a look at lita-karma for an example of this. I'm not super happy with the modification of global state in order to do this. There is probably something we can do to make this pattern easier in a future version of Lita.

You received this message because you are subscribed to the Google Groups "Lita" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
For more options, visit

Ingo Weiss

Jul 30, 2015, 5:51:37 PM7/30/15
to Lita,,
Thanks, Jimmy - clearing and re-defining routes in the 'before' block worked well!

Reply all
Reply to author
0 new messages