NWRUG

North West Ruby User Group

NWRUG Quiz: 99 Bottles of OO Programming

This exercise is taken with permission from 99 Bottles of OO Programming, by Sandi Metz and Katrina Owen. All material remains their property.

The exercise

The exercise is to write some code that outputs the "99 Bottles of Beer" song. We'll work on the exercise for 30 minutes. Most folks don't finish in 30 minutes so don't worry about how far you get. Afterwards we'll be looking at four pre-written solutions and discussing their relative merits and disadvantages.

Prerequisites

You will need Ruby 1.9 or above installed on your machine. Check which version you have with the following command:

ruby --version

If you don't have a new enough version of Ruby, follow the instructions on ruby-lang.org to install it.

You will also need the Minitest testing library version 5 or above. You can check which version you have with the following command:

gem list minitest

If you don't have Minitest version 5 or above, install it with the following command:

gem install minitest --version "~> 5.9"

Getting the exercise

There is a repository on Github that will help you get set up:

git clone --depth=1 --branch=exercise https://github.com/sandimetz/99bottles.git

The directory structure should look like this:

├── lib
│   └── bottles.rb
└── test
    └── bottles_test.rb

Doing the exercise

The test suite can be run by running the following command from the project directory:

ruby test/bottles_test.rb

The test suite contains one failing test and many skipped tests. Your goal is to write code that passes all of the tests. Compete the exercise by following these steps:

  • run the tests and note the failure
  • write only enough code to pass the failing test
  • unskip the next test

Repeat the steps until no tests are skipped and you've written code to pass them all.