O'Reilly logo

Take My Money by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unit Testing Our Logic

Before we move on from the shopping cart to payment and checkout (coming up next in Chapter 2, Take the Money), I want to show some of the tests that I wrote to drive the AddsToCart object because they show a technique that we’re going to use as we work with our business logic and third-party services. Specifically, I used RSpec’s verifying doubles when testing AddsToCart to isolate the test from the database and allow us to verify the workflow logic without dependency on any other part of the code.

Note that in order to run the tests, you need to have created the PostgreSQL database (rails db:create:all and rails db:migrate), and that PostgreSQL must be running.

Now, the workflow test:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required