Course Summary

Grace’s gift card request started as one sentence, “Customers buy one, and spend it over several visits,” and ended as a report she could act on.

Before you opened Quill’s branch, you had an intent with her answers next to your questions, criteria in pence, and, for each criterion, a test you’d seen fail. When you ran those tests against quill/gift-cards, they showed which criteria pull #31 meets, which it misses, and which question only Grace can settle.

The student discount went the same way earlier in the course, from “Students get 15% off” to a question about free books that a run made concrete enough for Grace to answer.

The Routine for the Next Change

A change that arrives with a tidy description and a green run can feel finished. The routine below gives you an order to work in instead, and each step leaves something written down or run:

  1. Write the intent before you open the diff. Record the problem, what’s true afterward, what must not change, and what’s out of scope, from the request alone. Where two readings of the request give different results, find a real basket that shows it and take the question to whoever asked. Under Grace’s “15% off” request, order-1 cost either 2550p or 2400p, depending on whether the free book counted.

  2. Turn the intent into criteria someone else can check. Write given/when/then examples with exact inputs and results in pence, covering a normal case, a boundary, an empty case, and an invalid one. Add the examples that must not change and the invariants every example keeps. Then invent a wrong version that passes them all, and add the example that rules it out, as criterion 9 did for the discount on the catalogue value.

  3. Read the tests, and their changes, before the code. Find the tests for the code the change touches by searching test/ for the affected function, and read each of those test bodies as an example of intended behavior, trusting the body over its name. List what the tests don’t check, and describe a green run as “these examples work.”

Then run git diff <base>..<branch> -- test/.

Ask three questions of every edited test: Did the expected behavior change, does the intent say so, and what did the old test check that no remaining test checks? If the intent still requires that behavior, keep a test that checks it.

  1. Write one test per criterion, and see each one fail. Act through the functions a caller uses, assert what the caller sees, and work out expected values from the request, not from the code. Run the test before the change exists, or against code you broke on purpose, and read the report for the values your criterion predicts.

  2. Judge the change against your criteria. For each criterion, report whether the change meets it, misses it, or needs a decision from the person who asked, along with the test that shows it. Trace every failure before you count it, and list what your tests don’t reach.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.