Exercise 006: Refactor Given/When Purpose Mismatch
Related Smell: 006 - Given/When Purpose Mismatch
Purpose
- Learn to identify the
Given/When Purpose Mismatch
smell. - Understand the different meaning of the steps
Given
versusWhen
even 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
When
should become aGiven
step. - What's wrong using a
When
step?
Hint C
- The step
When the customer is created
should be replaced. - This
When
has 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 Mismatch
smell. - Which existing 'Given' step can we you instead?
Step by Step Walkthrough
- The step
When the customer is created
should be replaced. - We can use this
Given
step insted: Find the two remainingGiven/When Purpose Mismatch
smells
Remove all smells
- Repeat the previous solution in the scenario
Scenario: Cannot create two customer with the same name
andScenario: Should find customers by name