Ruby On Rails Lesson
Comparing Figure 8.1 with Figure 7.11, we see that the signin form (or, equivalently, the new session form) is similar in appearance to the signup form, except with two fields (email and password) in place of four. As with the signup form, we can test the signin form by using Capybara to fill in the form values and then click the button.
In the process of writing thetests, we’ll beforced to design aspects of the application, which is one of the nice side effects of test-driven development. We’ll start with invalid signin, as mocked up in Figure 8.2. As seen in Figure 8.2,
when the signin information is invalid we want to re-render the signin page and display an error message. We’ll render the error as a flash message, which we can test for as follows:
(We saw similar code in Listing 7.32 from the exercises in Chapter 7.) Here the selector element (i.e., the tag) we’re looking for is
Recalling that the dot means ‘‘class’’ in CSS (Section 5.1.2), you might be able to guess that this tests for a div tag with the classes "alert" and "alert-error". We also test that the error message contains the text "Invalid". Putting these together, the test looks for an element of the following form: