Exercise 006: Refactor Given/When Purpose Mismatch
Related Smell: 006 - Given/When Purpose Mismatch
Purpose
- Learn to identify the
Given/When Purpose Mismatchsmell. - Understand the different meaning of the steps
GivenversusWheneven the functionality is the same.
Your Task
Within the Customer.feature file there are multiple occurances of this smell. The exercise is prepared in a way that you only need to refactor steps in the scenarios. Be aware that this is not always the case.
Find all scenarios with the smell and replace the When steps with Given instead.
Solution
Hint A
- Find all occurances of the smell. You are looking for three scenarios.
Hint B
- The first occurance is here:
- Identify which
Whenshould become aGivenstep. - What's wrong using a
Whenstep?
Hint C
- The step
When the customer is createdshould be replaced. - This
Whenhas two purposes: create an customer and focus on the error handling in the code. - We only want to verified the creation of the 2nd customer, the 1st is the
Given/When Purpose Mismatchsmell. - Which existing 'Given' step can we you instead?
Step by Step Walkthrough
- The step
When the customer is createdshould be replaced. - We can use this
Givenstep insted: Find the two remainingGiven/When Purpose Mismatchsmells
Remove all smells
- Repeat the previous solution in the scenario
Scenario: Cannot create two customer with the same nameandScenario: Should find customers by name