Exercise 005: Refactor Intermediate When Steps
Related Smell: 005 - Intermediate When Steps
Purpose
- Learn to identify the
Intermediate When Stepssmell. - Learn how to avoid multiple
Whensteps and understand that multiple actions lead to unclear scenarios.
Your Task
Within the Customer.feature file there are scenerios with multiple When steps. One of those stores an intermediate result to verify it afterwards. Find the Whensteps and merge them so that the intermediate result is not necessary anymore.
Solution
Hint A
- You are looking for a second intermediate
Whenstep that is searching for all customers. - Make sure you also consider
Andsteps.
Hint B
- The relevant step is
And all customers are searched - Look at the implemenation. Why is the
Whenstep necessary?
Hint C
- The relevant step is
And all customers are searched - The
And all customers are searchedstores a count, which is checked by theThenstep. - Check the name of the scenario, how can the existing steps be replaced with a step which expresses the intention more clearly?
Step by Step Walkthrough
- The relevant step is
And all customers are searched - The scenario is create a customer and find it afterwords.
- Searching and counting doesn't clearly express this business need.
- Instead the
Thenstep should find by name the created customer and check if it matches. - Replace
And all customers are searchedandThen the number of customers found is 1withThen the customer can be found