Exercise 005: Refactor Intermediate When Steps
Related Smell: 005 - Intermediate When Steps
Purpose
- Learn to identify the
Intermediate When Steps
smell. - Learn how to avoid multiple
When
steps 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 When
steps and merge them so that the intermediate result is not necessary anymore.
Solution
Hint A
- You are looking for a second intermediate
When
step that is searching for all customers. - Make sure you also consider
And
steps.
Hint B
- The relevant step is
And all customers are searched
- Look at the implemenation. Why is the
When
step necessary?
Hint C
- The relevant step is
And all customers are searched
- The
And all customers are searched
stores a count, which is checked by theThen
step. - 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
Then
step should find by name the created customer and check if it matches. - Replace
And all customers are searched
andThen the number of customers found is 1
withThen the customer can be found