Skip to content

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 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 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 Whenstep 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 the Thenstep.
  • 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 searched and Then the number of customers found is 1 with Then the customer can be found