Part 2: Happy paths for filtering movies
-
Complete the scenario
restrict to movies withPGorRratingsinfilter_movie_list.feature. For now, you can complete this using just the existing step definitions inweb_steps.rbto check and uncheck the appropriate boxes, submit the form, and check whether the correct movies appear (and just as importantly, movies with unselected ratings do not appear).Before moving on, verify that this scenario passes with
bundle exec cucumber features/filter_movie_list.feature.
-
Since it’s tedious to repeat steps such as
When I check the "PG" checkbox,And I check the "R" checkbox, etc., create a step definition to match a step such as:Given I check the following ratings: G, PG, RThis single step definition should only check the specified boxes, and leave the other boxes as they were. You should write this new step definition in
movie_steps.rb, filling in the empty step definition provided. To test the step, feel free to modify the scenario you just completed; this isn’t required, though, since you’ll also use this new custom step in the other scenario infilter_movie_list.feature.📌 HINT: this step definition can reuse existing steps in
web_steps.rb, as shown in the example in Section 7.8 in ESaaS.
-
Similarity, since it’s tedious to specify a step for each individual movie we should see, add a step definition to match a step such as: “Then I should see the following movies:“.
📌 HINT: Start from the starter code in
movie_steps.rb. You can check out a default implementation for “I should see” inweb_steps.rb, or just reuse the actual steps fromweb_steps.rbas described above.
-
For the scenario
all ratings selected, it would be tedious to useAnd I should seeto name every single movie. That would detract from the goal of BDD to convey the behavioral intent of the user story. To fix this, complete the step definition that will match steps of the form:Then I should see all the moviesinmovie_steps.rb.📌 HINT: Consider counting the number of rows in the HTML table to implement these steps. If you have computed the
rowsvariable as the number of table rows, you can use the assertionexpect(rows).to eq valueto fail the test in case the values don’t match.
- Use your new step definitions to complete the scenario
all ratings selected. SUCCESS is when all scenarios infilter_movie_list.featurepass with all steps green.