Refactoring spec test code