Archive for November, 2007

Taming the autotest Beast with FSEvents

autotest is a great tool and all, but it is simply resource intensive. Due to autotest’s implementation, it eats up CPU resources, not because the tests are always running (only after you modify your file), but because autotest continually polls each file in your directory, and sub directories, and checks to see if it has been modified.

This continual polling isn’t good for CPU resources. Now I may have some spare cycles to let autotest do its thang, but it also doesn’t sound too healthy for my hard drive.

Note: This is Mac OS X 10.5 Leopard specific.

Along Comes a Leopard

Whilst reading the Arstechnica review on Leopard, I came upon the section on the File System Events (FSEvents) that was introduced in 10.4 actually (for Spotlight), but used once again for Time Machine. In Mac OS X 10.5 Leopard, the API was opened up for the public to consume.

File System Events (FSEvents)

In its simplest level, your application will notify FSEvents, that it wants to listen to a particular directory, and when that directory (or its sub directories) are modified, FSEvents basically triggers a callback in your application. This allows you to hook to, listen to file system changes, and react to accordingly.

This is exactly what I needed to calm the fury of the autotest beast.

Install RubyCocoa

Update: It looks like the code works on the stock Ruby and RubyCocoa out of the box actually. You don’t need to install the latest version.
First of all, you need to install RubyCocoa, as this provides us with the bindings required to communicate with FSEvents. As I installed Ruby via MacPorts, I opted to do a source install (the MacPorts at present, is one version behind). I did run into trouble, encountering this error “file is not of required architecture“.

If you ever needed a reason to actually use RubyCocoa, let this be your reason!

Taming the beast

Once installed, dump this little gem into your ~/.autotest file:

For an easy to copy dump, click “view plain“.

Now when you run autotest, you’ll run into something like this:

/Users/aizat/.autotest:4: warning: method redefined; discarding old run

Don’t worry about it, and feel free to ignore it.

With this code, you can also tame the beast. There you have it, a much saner autotest, only for Mac OS X 10.5 Leopard.

Comments (20)

Building RubyCocoa with Ruby MacPorts Installation

First I tried installing RubyCocoa via MacPorts, but that failed. Unbothered, I went straight to the RubyCocoa page, and noticed it was running a newer version, v0.13.

So I happily downloaded the tar ball, and followed their installation guide, but ran into a little problem:

/Developer/usr/bin/gcc-4.0 -o /Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default/RubyCocoa.framework/Versions/A/RubyCocoa -L/Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default -L/opt/local/lib -F/Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default -filelist /Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/RubyCocoa.build/Default/RubyCocoa.build/Objects-normal/i386/RubyCocoa.LinkFileList -framework Foundation -arch i386 -Wl,-single_module -compatibility_version 1 -current_version 1 -install_name @executable_path/../Frameworks/RubyCocoa.framework/Versions/A/RubyCocoa -dynamiclib -mmacosx-version-min=10.5 -undefined suppress -flat_namespace -arch ppc -arch i386 -arch ppc64 -arch x86_64 -lxml2 -lffi /opt/local/lib/libruby.1.8.6.dylib
ld: warning in /opt/local/lib/libxml2.dylib, file is not of required architecture
ld: warning in /opt/local/lib/libruby.1.8.6.dylib, file is not of required architecture
ld: in /opt/local/lib/libxml2.2.dylib, file is not of required architecture
collect2: ld returned 1 exit status
ld: warning in /opt/local/lib/libxml2.dylib, file is not of required architecture
ld: warning in /opt/local/lib/libruby.1.8.6.dylib, file is not of required architecture
ld: in /opt/local/lib/libxml2.2.dylib, file is not of required architecture
collect2: ld returned 1 exit status
ld: warning in /opt/local/lib/libxml2.dylib, file is not of required architecture
ld: warning in /opt/local/lib/libruby.1.8.6.dylib, file is not of required architecture
ld: in /opt/local/lib/libxml2.2.dylib, file is not of required architecture
collect2: ld returned 1 exit status
ld: warning, duplicate dylib /opt/local/lib/libxml2.2.dylib
lipo: can't open input file: /var/folders/Pz/Pz+BnoKJHVOVErgN6VsRJk+++TI/-Tmp-//cc7uvHOl.out (No such file or directory)
** BUILD FAILED **
setup failed
'system /usr/bin/xcodebuild' failed

file is not of required architecture“, what in the world?

Well no worries, I was still able to get pass it, just turn on the –build-universal=no flag when you configure.

ruby install.rb config --build-universal=no
ruby install.rb setup
sudo ruby install.rb install

Comments (2)

autotest-ting your Rails Application with Visual and Audio Feedback using Growl and mpg321

autotest is a commandline tool that comes packaged together with ZenTest. Designed to continually test your Rails application, autotest makes a slight notch easier by removing the need to repeatedly call the rake task to run your application’s various tests.

Note: autotest is not limited to the default Ruby Test::Unit::TestCase. It will even work out of the box with RSpec.

Installing autotest

autotest is actually in the ZenTest gem.
sudo gem install -y ZenTest

Go to your application root directory and run autotest and watch it go!
autotest

Dead simple right? But still slightly irritating having to switch back to the terminal to see the results of test. So lets spruce it up a little, lets make it notify us of the results.

Visual Feedback with Growl

Growl is a notification that is over layed on top of your desktop, so that other applications are able to notify/inform you of anything, generally updates. For example Adium uses it to notify you of people logging in or out.

Note: Growl is a Mac OS X application. For other platforms you’ll have to look at integration with their notification apps, for exampleknotify, or gnome-notification.

Combined together with Growl, you will continuously be notified of the current status of your test suite through a nice non disruptive interface. Thus helping to ensure the integrity of your code base.

Installing Growl

Download Growl and install it. But don’t eject the Disc Image yet. We have to install the growlnotify command as well. This has to be done via the command line, so pull up your Terminal again.

We need to find out where Growl has been mounted to.
mount | grep -i growl

Possible Result:
/dev/disk2s2 on /Volumes/Growl 1.1.2 (local, nodev, nosuid, read-only, mounted by aizat)

From here you can see it has been mounted on /Volumes/Growl 1.1.2. Now go back to your Terminal, and we’ll install growlnotify.

cd "/Volumes/Growl 1.1.2/"
cd Extras/growlnotify
sudo ./install.sh

By default growlnotify is installed into /usr/local/bin, your applications may not be able to see that this exists. So let’s find out.

Execute:
which growlnotify

Desired Result:
/usr/local/bin/growlnotify

Possible Result:
no growlnotify in /opt/local/bin /opt/local/sbin /usr/local/bin /bin /sbin /usr/bin /usr/sbin

We want the desired result, so what do you do if you don’t get it?
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bashrc

Now growlnotify is accessible by all new Terminal sessions.

Let’s give it a shot, and test out Growl!
growlnotify -m "Hey Tony, isn’t this just grrrrrrreat?”

Integrating Growl with autotest

We need to create a .autotest (yes with the period) file in your home directory.
touch ~/.autotest
open ~/.autotest

Now stuff this in there!

Note: Adapted from Wincent Knowledge Base. I also took the personal liability to move files to the ~/Library/Application Support/ directory as I thought it would be more appropriate. Your choice, just change as desired.

Now for the final touch, the elusive images!
mkdir -p ~/Library/Application\ Support/autotest
cd ~/Library/Application\ Support/autotest
curl -O http://blog.internautdesign.com/files/rails_fail.png
curl -O http://blog.internautdesign.com/files/rails_ok.png

Note: If you want, you can even change the images to whatever you want yourself, just change lines 12 and 14 to point to the image location.

autotest-ing

Now go to the root directory of your Rails application, and simply execute:
autotest

and you should soon be notified of the results of your test.

Note: You can further customize Growl in the System Preferences!

Audio Feedback

Visual feedback is cool, but it would be even more awesome if it had audio feedback to accompany it.

Note: This method is cross platform.

This was first described on FozWorks (read on how to Install)

As I aggregated my autotest images into the ~/Library/Application Support/autotest directory, I thought I’d dump the sound files in there as well. Just pay attention when you have to modify your ~/.autotest to accommodate the different path.

The only disappointment with the default sounds they provide is that, they are a little bit soft, and is often drowned out by my music player. But no worries, you can decide to use your own effects, or if your like me, increase the gain with Audacity.

In the mean time, anyone have some interesting replacement sound effects?

Comments

« Previous entries