autotest is a fantastic tool. If you’re not using it, you’re missing out on a large part of the joy that life has to offer.
For everyone else,
In any case, this is a really useful tool. Autotest won’t run in Test::Unit mode if you have a
spec directory, but rstakeout can be told to run any command when files change. It’s not as smart as autotest (it won’t match the command to the name of the file that changed).
Get rstakeout from one of my Subversion repositories.
rstakeout "command to run" 'files to watch' 'more files to watch'
It’s most useful when you can use Ruby’s file globbing instead of the shell’s. If you do something like
'**/*.rb', Ruby will recurse into all subdirectories. The shell will only go down a single directory, so quote the final arguments so they will be passed to Ruby.
Rerun a single unit test when the implementation or test file is saved:
rstakeout "ruby test/unit/user_test.rb" 'app/models/user.rb' 'test/unit/user_test.rb'
Run the unit tests when model files are saved:
rstakeout "rake test:units" 'app/models/*.rb' 'test/unit/*.rb'
Run a single functional test, then run flog and filter the output with grep. This will show if your code is becoming more complicated or less.
rstakeout "ruby test/functional/orders_controller_test.rb && \ flog -a app/controllers/orders_controller.rb | \ grep 'OrdersController#checkout'" 'app/**/*' 'test/**/*' Loaded suite test/functional/orders_controller_test Started .............................. Finished in 3.536267 seconds. 30 tests, 74 assertions, 0 failures, 0 errors OrdersController#checkout: (56.5) OrdersController#checkout_with_google: (17.6) OrdersController#checkout_with_paypal: (15.9)
Lather, rise, repeat with Heckle or any other testing tool.
I’m using this to generate PDF documents using my automated system for PeepCode Press.
rstakeout "ruby script/generate code_review" '**/*.textile'
I use a shell shortcut to reuse the previous command.
$ some --long shell command $ rstakeout "!!" 'files/**/*'
Ryan Davis pointed out that you can do something similar with flog and autotest by hard-coding this into your ~/.autotest file:
Autotest.add_hook :green do |at| system "flog app/controllers/users_controller.rb | grep \\#update" end
rstakeout = 73.7304101610032 autotest = 909.440236256987 ratio = autotest / rstakeout = 12.3346694297654 # <-- zomg! look here!!! # I have no idea what these numbers are here for, # or what they mean. ratio - Math::PI = 9.19307677617561 target = autotest / Math::PI = 289.483818093921 target - rstakeout = 215.753407932918
Somehow, it’s been a year of PeepCode!
And the first PeepCode Press PDF is now available for purchase in draft form. Rails Code Review is seventeen chapters of common mistakes in Rails apps, and examples of how to write better code instead.
Finally, I have about 15 PeepCode t-shirts that were printed with an experimental process. Early users have reported that the printing washes off after the first laundering. But hey, at least you’ll have a nice black t-shirt! I’ll send you one at my expense, anywhere in the world.