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: