Writing a System Test
Explore how to write effective system tests in a Ruby on Rails app focusing on testing major user workflows such as widget creation and validation errors. Learn to implement controller actions and model validations that support these tests, helping ensure a consistent user experience across the app.
We'll cover the following...
System testing major flows
We want to test major flows, and there are two that we can see: correctly saving a widget and seeing validation errors. Our system test can’t reasonably test all the back-end business logic, and doesn’t need to exhaustively test each possible error case. We really only need to make sure that all fields that could have an error will show one. Fortunately, we can create a blank widget, and this will show validation errors for all three fields.
Because we don’t have JavaScript, our system test can use the standard test case, ApplicationSystemTestCase.
Let’s start with the validation errors because the back end is already faked out to provide errors no matter what. This test will go to the new widget page, skip filling in any fields, click “Create,” and then validate that there are errors for each field.
We need something to happen when we click “Create,” so let’s implement ...