Code Coverage

Objectives

  1. Introduce a helpful tool for writing tests and ensuring clean and well-functioning code.
  2. Practice writing your own RSpec tests.

Introduction

How do we know we have enough tests, and that our tests cover all of our code?

Enter simplecov! simplecov is a tool that will measure your test run against the code paths in your code files and see if you're exercising them all. "Code Paths" includes method calls, conditional statements, loops, and anything that branches program flow.

This is important because you want to be able to know that every decision your program makes is being tested, no matter what.

Overview

This lab utilizes our Jukebox domain model. We have Jukebox and Song classes. You'll be using the simplecov tool to guide you to write tests that cover 100% of the code in our program.

Instructions

  1. Install the simplecov gem with gem install simplecov.
  2. Run your spec file with rspec.

You should see output at the end of the test results that looks something like:

Coverage report generated for RSpec to /Users/scottreynolds/code/ta/labs/simplecov/coverage. 14 / 33 LOC (42.42%) covered.
  1. Open coverage/index.html in your browser window to view the report. Try to get the coverage to 100% by writing RSpec tests. Every time you add a test, run rspec to see if the test is passing. Every time you run rspec, simplecov will also run. Continue to open the coverage/index.html file after every run to see your updated test coverage. Toggle the individual file view to see which lines are covered by your tests.

Resources

Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us