Code Challenge Prep: Creating Test Objects Efficiently

Mike Smith
3 min readOct 7, 2020

--

If you’re approaching your first Code Challenge at the Flatiron School, there are two things you should know in advance.

First of all, time will seem against you. Starting strong takes a bit of consistency, so use these insights to get in those reps and shave 10 minutes off you’re opening code.

Secondly, there is no RSpec during a Code Challenge.

That’s right…no RSpec. Up until this point, you’ve been “chasing that green” and “passing labs”. Your Code Challenge will have none of that. You likely hear the term “you have to write your tests” thrown around. It is worth noting that RSpec is its own language. Tests are written in Rspec with their own keywords and methodology. Don’t worry- no one is expecting you to ‘write your own tests’ in RSpec. And while that is something you may want to learn, don’t worry about that for now- we got bigger fish to pry.

You will have a console.rb file at your disposal. This is where your test objects will live. Your test objects are instances of a class. You’ll be working with at least three classes. Here’s where you can begin to practice the first 20 minutes of your Code Challenge. Do these reps once or twice a day leading up.

The first step in these practice concepts is to imagine a relationship between three classes. Give them each 2 or 3 parameters for initialization.

Here, I’ve created an Attendant, Car, and Lot.
Now, jump down into your terminal and run your console.rb file. Make sure you have require ‘pry’ and and binding.pry within that file.

Next, while in pry, verify that your classes are active by simplying typing them into your terminal, capitalized.

You’re off to a hot start. Here’s where you can start to save a little bit of time by both creating and testing test objects while in pry. First, create two examples of your first class (in this case ‘Attendant’).

My creations are working, so now I’m going to copy/paste lines [4] and [5] into my console.rb file.

Repeat the process for any remaining classes….create, then copy/paste to console.rb.

Until you’ve populated some viable test objects.

Now, while still in pry, you can test the reception. Here, I’ll test my Attendant class.

And more of the same with my remaining classes. (Car tests not show).

And there you have it!

This is something you can practice with reps on your own leading up to your code challenge.

CAUTION: These testing strategies assume that all of your attr’s are writable! Check out Part 2 of this blog for more efficient strategies when some attributes are readers.

--

--