Autotest Growl Fail/Pass Smilies

John Nunemaker posted a handy tip on “setting up autotest to work with Growl”:
I use this all the time now however I didn’t like the ugly smilies (call me shallow if you like). I used “Wolfgang Bartelme’s”: “Smily Devkit”: to make a couple of PNG’s slightly more pleasing to the eye.
p=. ! Fail image)!
! Pending image)!
! Pass image)!
The zip file can be downloaded here: “”:
*Update* 17-08-07: Added ‘pending’ image for RSpec as requested by Aslak Hellesoy

A Ruby reject! that returns the rejected items

I often need to do a reject! and return the rejected items instead of the modified collection. This saves having to do a select beforehand.
An example of how accomplish this:

options = { :a => 1, :b => 2, :c => 3 }
rejects = Hash[* { |k, v| k == :b && options.delete(k) }.flatten]
assert_equal { :a => 1, :c => 3 }, options
assert_equal { :b => 2 }, rejects

This could be written as a method of the Hash class and an alternative for Array.
For Hash, the code would look something like:

class Hash
  def extract!
    Hash[* { |k, v| yield(k, v) && self.delete(k) }.flatten]
options = { :a => 1, :b => 2, :c => 3 }
rejects = options.extract! { |k, v| k == :b }
assert_equal { :a => 1, :c => 3 }, options
assert_equal { :b => 2 }, rejects

If I am missing something obvious in Ruby that accomplishes the same, please leave a comment.

TheLucid Typo theme now works with version 4.1

TheLucid Typo theme finally works with version 4.1 of Typo.
Please bear in mind that this is quick-fix and and there will still be a Version 2 release sometime in the near future.
The new release can be downloaded below:
There are a couple of improvements such as cookies remembering which colour scheme and layout have been selected along with some IE fixes.
Thanks to everyone who notified me of browser issues etc. and I hope to release v2.0 as soon as possible (for both Typo and Mephisto).

Using autotest when developing Rails plugins

I am a great fan of ZenTest’s ‘autotest’ tool and use it continuously whilst developing Rails apps. Up until now I’d not found a way to use autotest while developing plugins.
h3. The problem
After some digging around in the ZenTest source, it turns out that autotest looks for files that are prefixed with test_ however the standard convention in Rails is to use a suffix e.g. base_test.rb. You could simply prefix your tests instead of using suffixes and modify the test file pattern in the Rakefile, however this feels wrong.
I noticed that autotest looks for a .autotest file in the current directory before looking in the home directory meaning that getting autotest to run for plugins is surprisingly simple.
h3. The solution
Create an .autotest file in the root of the plugin directory containing the following:

global_autotest_file = File.expand_path('~/.autotest')
load(global_autotest_file) if File.exists?(global_autotest_file)
class Autotest
 def tests_for_file(filename)

You can now cd into the plugin dir, run autotest and all works as it does in a Rails app[1]. Also as this file loads the .autotest file in the home directory, any Growl notifiers etc. setup there will all work fine.
fn1. The only difference is that all tests are re-loaded when a test file is saved. This is not an issue for the majority of plugins, if it is, then it’s probably a sign that the tests need optimising.