Agile Web Development with Rails 6 - more system tests need correcting (Iteration H2)

On Iteration H2, we run systems tests for the first time. There are instructions to fix products_test.rb but there are a number of other places to fix. After the fix in the book, the tests still generate 2 failures and 5 errors (at least for me – but I’m pretty sure I haven’t deviated from the book and all of the other tests (controllers and models) run find and my application seems to behave fine in the development environment).

Most of the problems seem to stem from the functionality that is no longer the default from scaffolding.

  • Carts test generates 2 errors in looking for “Back.”
  • Carts test generates a failure looking for the default cart destroyed message.
  • Line items test generates an error in creating a line item (“couldn’t find Product without an ID”).
  • Orders test has 2 errors for updating, one because it is unable to find pay type that is not disabled and one because the button doesn’t say “Update Order”
  • Orders test errors in creating (Unable to find Address) – I assume that’s because the cart is empty and doesn’t display the form.

Most of these tests (with the exception of outdated nav and messaging in the carts test) are for functionality that doesn’t match what we need and those tests can be commented out.

2 Likes

Hey, sorry for taking a while to reply—was on vacation.

As background, the code listings and terminal output in the book is generated from a script that does what the book is explaining to do, so the first two things I can suggest would be:

  1. Compare your code with the downloadable examples as of this chapter. The code in Interation H2 is based on what’s in depot_pc so you can use that as a reference to see what’s working
  2. If that doesn’t work, can you can post your work-in-progress repo on e.g. GitHub, I can take a look.

I guess all that’s to say, the code should work and tests should pass or at least behave the way the book says. If that’s not your experience, try the two things above and, it’s always possible Rails changed something that breaks the book in a subtle way…it wouldn’t be the first time :slight_smile:

2 Likes

It seems that the problem here is that in Rails 6, when generating a scaffold, it also generates system tests. I believe this behavior was added in 6 and not present in 5.1. By the time we run our first rails test:system in Iteration H2, we are presented with many failing tests from all of the automatically generated tests from the previous iterations.

Easiest solution is to append all of the scaffold commands with —skip-system-tests.