tyrbo/turingbot — pull request #1 by JoshCheek (2014-08-23 20:24:07+00:00)
Title: Add integration tests

Need something in place to enable refactoring.

Potential refactorings floating around in my brain:

* Toplevel object's responsibility is to just protect the lib from the big bad world (in this case, that's `Turingbot::Bot` protecting the rest of the lib from Rack). Everything else can exist independently of this, so probably pull process_message and channel logic and so forth out into another object that can be tested without sending a web request.
- push channel checking down into `process_message`
- extract `process_message` into an object, initialized with the name and channel (then can test/fix the regex -- e.g. if bot name was "Turing|Bot", and someone sent a message to "TuringAdmissions")
- would probably rename Bot to App, to me it's just a way to wire the bot into Rack, but the bot itself should be independent of the fact that it's being served in a `Rack` app. I should be able to use it with full functionality from within another lib (ie I could bring it into apply.turing.io which could post messages to staff channel when someone applies), but right now, logic about when to respond is integrated with knowledge of rack
* `Turingbot::Command::URL` and `Path` should be injectible
* de-singleton `Turingbot::Command::Commands` (I should be able to run two different bots at once with different sets of commands). I don't really know what this looks like yet. Maybe fine to have a singleton CommandRegistry if running a command is decoupled from the global list. Or maybe the toplevel (our rack app) wires it all together. At the very least, I should be able to test its behavoiur without fucking up the object (https://twitter.com/josh_cheek/status/502665494596702208).
* I dislike the side effect of sending the message down in the command. General feeling is to stick that in its own object, and pull it as high as possible. I don't exactly know how high, maybe all the way up into Bot. Then I can then hit the bot and get back a list of messages it would send, and then choose to send them or do something else with them if I want (log them and then send them, send them and send myself an email of every message sent, compose bots out of other bots, etc)