Jabbering with Action Messenger
Posted by Trejkaz Mon, 08 May 2006 13:24:57 GMT
Want to send instant messages from your Ruby on Rails app with the minimum amount of code and the maximum amount of testability?
Then say hello to… Action Messenger
Some time ago, the Typo weblog software introduced a new feature, where notifications of new articles or comments could be delivered via XMPP, or as it’s more commonly known, Jabber. The one catch with the feature was that it depended on the older Jabber4R library, which under certain versions of Ruby, simply failed to work. Jabber4R has serious bugs in there which cause it to deadlock under any newer version of Ruby.
I wanted to use the feature rather badly at the time, so I patched it to use XMPP4R instead. The patch still hasn’t been accepted, allegedly due to a lack of tests. Granted, unit testing is big in the Rails world, but the original Jabber notification code didn’t have unit tests either, so I just see this as an enormous hypocrisy where the developers don’t write their own tests, and think that it’s everyone else’s responsibility to write the tests for them.
So in any case because of this, it’s likely that under the current state of affairs, the existing Jabber support in Typo will remain broken indefinitely.
After all of that, I started thinking about unit testing the Jabber messaging part. The main problem is that a Jabber communication library generally requires a network connection to operate. Whereas this is usually avoided by using mock objects, XMPP4R exposes rather a lot of different classes, and mocking the entire library out is probably just a little unreasonable.
So what you do is write a layer which has less things to mock out, and that’s the basis of Action Messenger. However, I couldn’t stop at merely having this layer for mocking. I had to go and make it possible to send a Jabber message with three trivial lines of code (two in the messenger layer, setting up the recipient and the body, and one in the controller to tell the messenger to send the message.)
So that’s what Action Messenger is. There isn’t much to it right now, but what’s there is heavily unit tested, and has convenience built-in for making your own code which uses it, more testable.
Enjoy, and as always, send complaints this way. :-)