For this lesson, you will build the "Zooniverse", a fictional location from the television series, The Mighty Boosh.
- Build objects in Ruby
- Understand object composition
- Practice test-driven development (TDD)
Run the following:
et get object-oriented-marathon
cd object-oriented-marathon
bundle
bundle exec rspec
bundle exec rspec
You'll see something like
An error occurred while loading ./spec/1_gorilla_spec.rb.
Failure/Error: require_relative "../lib/cage"
LoadError:
cannot load such file -- /Users/beinneighe93/launch/bos23/object-oriented-marathon/lib/cage
# ./spec/spec_helper.rb:5:in `require_relative'
# ./spec/spec_helper.rb:5:in `<top (required)>'
# ./spec/1_gorilla_spec.rb:1:in `require'
# ./spec/1_gorilla_spec.rb:1:in `<top (required)>'
The important bit of this message is cannot load such file -- /Users/beinneighe93/launch/bos23/object-oriented-marathon/lib/cage
, which tells us that Ruby is looking for, but can't find, cage.rb
.
Create this file and rerun the test, repeating this process until you no longer encounter any missing-file errors.
Next, follow the Red-Green-Refactor cycle, letting the tests guide you. In other words:
Run the tests and note the failures.
bundle exec rspec
// failing test
Write some code to make the test pass.
bundle exec rspec
// passing test
Evaluate and improve what you have written. Refactor your code by extracting duplication into methods. Extract functionality into classes.
Rerun your test suite after every refactor to ensure that your changes don't break your application.
After you've completed the exercise, watch us work through the challenge by checking out the video solution below.
{% show_solution %} {% vimeo_video '153573063' %} {% endshow_solution %}