The Blog

Posts from April 2011

Apr 29

Speed Up Testing With Spork

By David Czarnecki

If you TATFT, embrace red-green-refactor, or you just want to speed up execution of your test suite, you might want to take a look at Spork. It will fork a test server for you that pre-loads your environment allowing you to run individual tests or your entire test suite without the startup cost of the loading the environment for each test or test suite run.

Here’s a quick setup guide for testunit with spork-testunit, but if you’re using RSpec, then it should “just work”.

  1. Add the following to your project’s Gemfile.
 group :test, :development do
   gem 'spork'
   gem 'spork-testunit'
 end
  1. Run “bundle install” to install the gems.

  2. Run “spork testunit –bootstrap” to bootstrap your test/test_helper.rb file.

  3. Move your current test_helper “stuff” into the Spork.prefork block.

  4. Start spork in a terminal in your project directory.

  5. Run your full test suite in a another terminal in your project directory, “testdrb -Itest **/*.rb”. It should run without any environment startup “cost”. You can run individual tests, just the unit tests, just the functional tests, etc. in a similar fashion.

It seems like the 0.9.0.rc5 version of Spork is the one that handles underlying code changes correctly so you don’t have to restart spork each time you change controller or model code.

You can find more hilarity over on my Twitter account, CzarneckiD.

Apr 19

Capistrano and Campfire After-Deploy Hook For The Lulz

By David Czarnecki

We recently started using capistrano-mountaintop to announce when deploys to our environments are taking place. This morning, @andkjar noted that it’d be nice to see if the deploy was successful or not since it pastes the deploy log and it’s long enough that you might not see whether or not the deploy was successful. This simple addition to deploy.rb checks the deploy log for success or failure and pastes an appropriate image into our Campfire room.

{% gist 929219 %}

Success results in:

Failure results in:

You can find more hilarity over on my Twitter account, CzarneckiD.

Apr 3

Reduce Your Open Source Technical Debt Using These Easy Steps!

By David Czarnecki

Do you know what all those GitHub projects you’ve got forked to your personal GitHub account are? Technical debt. Follow these easy steps to enjoy a debt-free open source lifestyle.

  1. Watch a project, don’t fork it.

Your GitHub news feed is your friend and you’re already using a news aggregator right? Watching a project will ensure you’re kept up-to-date on project happenings (commits, issues, pull requests, etc.) without having to fork the code.

  1. If you fork a project, contribute something back to the project.

I did this awhile back with a project called soulmate. It got mention on Hacker News, I checked it out, saw there were no tests, over 300 watchers, and felt charitable. I forked the project and contributed my updates to show an integration test and start and stop Redis automatically when running the tests.

Once the project integrated my changes, I deleted my fork. Why? I was never going to do anything with soulmate, so why keep the fork around? If the project owner comes back to you and requests changes to your pull request, make them and move on. Delete your fork unless you’re going to contribute more to the project. If you are going to contribute more to the project, follow step #3 below.

  1. If you fork a project, configure a remote branch to track upstream project changes.

When you fork a project on GitHub, a remote branch for tracking is not automatically created for you. By doing this, you can stay in-sync with the main project’s codebase.

{% gist 900703 %}

I am proud to say that I am living a debt free lifestyle on my GitHub account. The 3 forked projects I have up there now, all have open pull requests to their respective project’s main codebase. Once those pull requests are accepted or rejected, I will delete my forks unless I am going to contribute more to the project.

You can find more hilarity over on my Twitter account, CzarneckiD.