A while back I read Steven Harman's post about using AutoHotKey on Windows to alleviate the pain of writing underscores into your test names to do BDD-style naming. I am using David Tchepak's version of the macro because I like the way it works and it has the sweet visual tray icon. This macro is a godsend when writing english-sentence-ish names for tests and fixtures, as the underscore is a super pain in the ass, but really helps with readability, and if you are using a tool like SpecUnit.net that parses names on underscores, they're a necessity.

The only friction I've had really using this is that when I am inheriting from a base class in a test fixture, and the macro is running, I have to hit ESC before moving on to the : and the inherited class name. Yeah, it's not a huge deal, but in the spirit of keeping the hands on the home keys as much as possible, I wanted to reduce this little bit of friction. On the plane ride home from CodeStock I had nothing better to do, so I fired it up and made the required script modification

What I needed to have happen was that the test naming mode would toggle off when I typed : (colon) so that I could do test_fixture_name:acts_as_base_fixture_name. Unfortunately, AHK doesn't have a named keyboard input for colon, so I had to do some digging and figure out what it was seeing when I typed :

If you are running a script, you can double-click the icon in the tray and open a window that lets you see the captured keystrokes. Simply type what you are looking to capture and then hit F5 to refresh and see it. On my machine, colon maps to Shift + Special Character 027, which looks like +SC027 in AHK script. With that, I just jumped to the bottom of the script file and added a new key handler that looks like this:

$+SC027:: ;Colon Pressed
SetTestNamingMode(false)
Send, {SHIFTDOWN}{SC027}{SHIFTUP}
return

Then just reload the script, and you will leave test naming mode upon pressing :

Technorati Tags:  
,