Skip to main content

Code Retreat Roundup: GitHub Toolbox

12-08-11 Rob Tarr

Rob and Rob spent a thrilling day practicing code, and they came back with a cache of GitHub goodness.

Last Saturday, Rob and I went down to Cincinnati for the Global Day of Code Retreat. We spent the entire day practicing code. Yes, that’s right – practicing. We wrote and tested code for 45 minutes, talked about what we had done, deleted our code, and then started over. It was a very useful exercise which Rob will be blogging about very soon.

Since Rob is going to write about how incredibly beneficial the day was for us, I wanted to highlight some of the cool tools that I discovered while I was there. The day was centered around developing using TDD, so there’s definitely a testing slant to my list. Now, I’ll be the first to say that I definitely fall into the camp of wanting to write tests for my code; but not having done it on a project, I wasn’t sure where to start. After the Code Retreat, I feel much more confident in my ability to write good tests, and I think that these tools will help me to do just that.

rspec-given

I had the opportunity to pair with @pkananen on some Ruby, using RSpec for testing. As I was trying to figure out how to start writing the tests, Peter suggested we try given. It’s basically a simple syntax for quickly writing very clear, readable tests.

The first RSpec test I wrote looked something like this:

describe "conways" do
  cell = Cell.new
  
  it "should live" do
    cell.lives?(0).should be_false
    cell.lives?(1).should be_false
    cell.lives?(2).should be_true
    cell.lives?(3).should be_true
    cell.lives?(4).should be_false
  end

end

This is an interpretation of this same test using given:

describe Cell do
  Given(:cell) { cell = Cell.new }
  
  context "with 0 neighbors" do
    Then { cell.lives?(0) == false }
  end

  context "with 1 neighbor" do
    Then { cell.lives?(1) == false }
  end

  context "with 2 neighbors" do
    Then { cell.lives?(2) == true }
  end

  context "with 3 neighbors" do
    Then { cell.lives?(3) == true }
  end

  context "with 4 neighbors" do
    Then { cell.lives?(4).should be_false }
  end
end

I haven’t played with these a lot, but I feel like the rspec-given tests may be more expressive than the straight RSpec tests. It provides a simple syntax that I think most people could read and understand what the test results should be.

Guard

During another session, I paired with @MattBrewer and saw another really cool tool – Guard. During my first two sessions, the process was something like this:

  1. Write test.

  2. Write code.

  3. Save code.

  4. Switch to terminal.

  5. Run tests.

  6. Switch back to TextMate.

  7. Fix code.

  8. Repeat as necessary.

  9. Move on to next test.

Working with Matt, however, that workflow changed:

  1. Write test.

  2. Write code.

  3. Save code.

  4. Watch tests run in background.

  5. Fix code.

  6. Repeat as necessary.

  7. Move on to next test.

Step 4 here was the frosting on the cake. Every time we saved a file, Guard ran the tests. With a terminal window open off to the side, we could instantly see the results of the tests. Seeing as we only had 45 minutes to get as much of the problem solved as we could, this was a very useful thing to have running.

Setting up Guard was pretty easy, and I found that it will also do things such as rebuilding your gem set if you update your gemfile. I also installed a growl gem, so I now get test/gemfile build results in growl notifications. I’m sure it does a lot more, and I’m anxious to spend more time finding out what it can do.

Consular

While I was setting up Guard (with a few pointers from @cromwellryan), Ryan told me about this little app. Between running multiple Rails apps and other miscellaneous things, it’s not uncommon for me to have Terminal running with multiple tabs open for each project I’m working on. Consular provides a way to define sets of windows/tabs and provides a way to execute commands in those windows/tabs at start up. So, I’m setting up consular files to open up work spaces for my projects and launch the server and any other appropriate files for those projects. AWESOME!

I wrote a quick little consular script for starting up my Rails projects:

window do
  run 'echo -n -e "\033]0; Project Name - Rails Server \0007"'

  before { run 'cd projects/project-folder' }
 
  run "rails s"

  tab "named test" do
    run 'echo -n -e "\033]0; Project Name - Tests \0007"'
    run "guard"
  end

  tab "named project" do
    run 'echo -n -e "\033]0; Project Name - Files \0007"'
    run "ls"
  end
end

What other tools are you using?

Today, there are so many tools to help us build things faster and more efficiently that it is sometimes hard to keep up with them. Frankly, these tools solved some problems that I didn’t even really know that I had. I am getting the feeling that after using these for a little while some of them will quickly become essential parts of my development toolbox.

I would love to know of other cool things I can add to my toolbox. Leave me some comments below or on Twitter.

And if you haven’t checked out GitHub’s Octodex, you should. The Octocat is waiting.

Related Content

See Everything In

Want to talk about how we can work together?

Katie can help

A portrait of Vice President of Business Development, Katie Jennings.

Katie Jennings

Vice President of Business Development