Code Retreat Roundup: GitHub Toolbox

Original post can be found at http://seesparkbox.com/foundry/code_retreat_roundup_github_toolbox

Code Retreat Roundup: GitHub Toolbox

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:

1
describe "conways" do
2
  cell = Cell.new
3
  
4
  it "should live" do
5
    cell.lives?(0).should be_false
6
    cell.lives?(1).should be_false
7
    cell.lives?(2).should be_true
8
    cell.lives?(3).should be_true
9
    cell.lives?(4).should be_false
10
  end
11

12
end
view raw ruby-rspec This Gist brought to you by GitHub.

 

This is an interpretation of this same test using given:

1
describe Cell do
2
  Given(:cell) { cell = Cell.new }
3
  
4
  context "with 0 neighbors" do
5
    Then { cell.lives?(0) == false }
6
  end
7

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

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

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

20
  context "with 4 neighbors" do
21
    Then { cell.lives?(4).should be_false }
22
  end
23
end
view raw ruby-given This Gist brought to you by GitHub.

 

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:

 

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

4
  before { run 'cd projects/project-folder' }
5
 
6
  run "rails s"
7

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

13
  tab "named project" do
14
    run 'echo -n -e "\033]0; Project Name - Files \0007"'
15
    run "ls"
16
  end
17
end
18

view raw Consular This Gist brought to you by GitHub.

 


tryjasmine.com

This was another thing I picked up from @pkananen. If you want to try your hand at writing tests for JavaScript (or CoffeeScript) then this might be a great place to start. It gives you a place to write your code and tests side by side. You can easily convert between CoffeeScript and JavaScript and it gives you a few built in macros to get started or just to quickly stub out tests.


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.

 

 

Views: 34

Tags: cincinnati, gdcr11, github, tips, tools

Comment

You need to be a member of Coderetreat to add comments!

Join Coderetreat

© 2014   Created by corey haines.

Badges  |  Report an Issue  |  Terms of Service